⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extendedattributes.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections.Specialized;

namespace CommunityServer.Components
{

	/// <summary>
	/// Provides standard implementation for simple extendent data storage
	/// </summary>
	[Serializable]
	public class ExtendedAttributes
	{
		public ExtendedAttributes()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		NameValueCollection	extendedAttributes = new NameValueCollection();

		public string GetExtendedAttribute(string name)	
		{
			string returnValue = extendedAttributes[name];

			if (returnValue	== null)
				return string.Empty;
			else
				return returnValue;
		}

		public void SetExtendedAttribute(string	name, string value)	
		{

			if((value == null) || (value == string.Empty))
				extendedAttributes.Remove(name);
			else
				extendedAttributes[name] = value;

		}

		public int ExtendedAttributesCount
		{
			get { return extendedAttributes.Count; }
		}

        protected bool GetBool(string name, bool defaultValue)
        {
            string b = GetExtendedAttribute(name);
            if(b == null || b.Trim().Length == 0)
                return defaultValue;

            return bool.Parse(b);
        }

        protected int GetInt(string name, int defaultValue)
        {
            string i = GetExtendedAttribute(name);
            if(i == null || i.Trim().Length == 0)
                return defaultValue;

            return Int32.Parse(i);
        }

        protected string GetString(string name, string defaultValue)
        {
            string v = GetExtendedAttribute(name);
            return (Globals.IsNullorEmpty(v)) ? defaultValue : v;
        }

		#region Serialization

        public SerializerData GetSerializerData()
        {
            SerializerData data = new SerializerData();
            //data.Bytes = Serializer.ConvertToBytes(this.extendedAttributes);
            
            string keys = null;
            string values = null;

            Serializer.ConvertFromNameValueCollection(this.extendedAttributes,ref keys, ref values);
            data.Keys = keys;
            data.Values = values;

            return data;
        }

        public void SetSerializerData(SerializerData data)
        {
//            if(data.Bytes != null)
//            {
//                try
//                {
//                    extendedAttributes = Serializer.ConvertToObject(data.Bytes) as NameValueCollection;
//                }
//                catch{}
//            }

            if(this.extendedAttributes == null || this.extendedAttributes.Count == 0)
            {
                this.extendedAttributes = Serializer.ConvertToNameValueCollection(data.Keys,data.Values);
            }

            if(this.extendedAttributes == null)
                extendedAttributes = new NameValueCollection();
        }
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -