/// <summary>
        /// 在没有定义的情况下,设置属性的值
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="dataType">类型</param>
        /// <param name="stringValue">属性值</param>
        public void AddOrSetValue <T>(string key, ClientPropertyDataType dataType, T value)
        {
            ClientPropertyValue v = this[key];
            string stringValue    = string.Empty;

            if (value != null)
            {
                stringValue = value.ToString();
            }

            if (v == null)
            {
                v = new ClientPropertyValue(key)
                {
                    DataType = dataType, StringValue = stringValue
                };
                this.AddNotExistsItem(v);
            }
            else if (v.DataType != dataType)
            {
                throw new ArgumentException(Translator.Translate(Define.DefaultCulture, "已存在键为{0}的属性,但类型为{1},与预期的类型{2}不一致。", key, v.DataType, dataType));
            }

            v.StringValue = stringValue;
        }
        public ClientPropertyValue(ClientPropertyDefine def, ClientPropertyDataType dataType, string stringValue)
        {
            InitFromPropertyDefine(def);

            this._DataType    = dataType;
            this._StringValue = InitDefaultValue(dataType, stringValue);
        }
		public ClientPropertyValue(ClientPropertyDefine def, ClientPropertyDataType dataType, string stringValue)
		{
			InitFromPropertyDefine(def);

			this._DataType = dataType;
			this._StringValue = InitDefaultValue(dataType, stringValue);
		}
Exemple #4
0
        /// <summary>
        /// 将PropertyDataType转换成.Net的数据类型
        /// </summary>
        /// <param name="pdt"></param>
        /// <returns></returns>
        public static Type ToRealType(this ClientPropertyDataType pdt)
        {
            Type result = typeof(string);

            TryToRealType(pdt, out result).FalseThrow("不支持PropertyDataType的{0}类型转换为CLR的数据类型", pdt);

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// 将PropertyDataType转换成.Net的数据类型
        /// </summary>
        /// <param name="pdt"></param>
        /// <returns></returns>
        public static Type ToRealType(this ClientPropertyDataType pdt)
        {
            Type result = typeof(string);

            TryToRealType(pdt, out result).FalseThrow(
                Translator.Translate(Define.DefaultCulture, "不支持PropertyDataType的{0}类型转换为CLR的数据类型", pdt));

            return(result);
        }
        private void InitFromPropertyDefine(ClientPropertyDefine def)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(def != null, "def");

            this._AlterKey    = def.Name;
            this._StringValue = def.DefaultValue;
            this._DataType    = def.DataType;
            this._StringValue = InitDefaultValue(this._DataType, def.DefaultValue);
        }
        private static string InitDefaultValue(ClientPropertyDataType dataType, string defaultValue)
        {
            string result = defaultValue;

            if (defaultValue.IsNullOrEmpty() && dataType != ClientPropertyDataType.String)
            {
                object data = TypeCreator.GetTypeDefaultValue(dataType.ToRealType());

                if (data != null)
                    result = data.ToString();
            }

            return result;
        }
Exemple #8
0
        /// <summary>
        /// 基本类型转换到PropertyDataType
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ClientPropertyDataType ToPropertyDataType(this System.Type type)
        {
            type.NullCheck("type");

            ClientPropertyDataType result = ClientPropertyDataType.DataObject;

            foreach (KeyValuePair <ClientPropertyDataType, System.Type> kp in _DataTypeMappings)
            {
                if (kp.Value == type)
                {
                    result = kp.Key;
                    break;
                }
            }

            return(result);
        }
        /// <summary>
        /// 在没有定义的情况下,设置属性的值
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="type">类型</param>
        /// <param name="stringValue">属性值</param>
        public void AddOrSetValue(string key, ClientPropertyDataType type, string stringValue)
        {
            ClientPropertyValue v = this[key];

            if (v == null)
            {
                v = new ClientPropertyValue(key)
                {
                    DataType = type, StringValue = stringValue
                };
                this.AddNotExistsItem(v);
            }
            else if (v.DataType != type)
            {
                throw new ArgumentException(string.Format("已存在键为 {0} 的属性,但类型为{1},与预期的类型 {2} 不一致。", key, v.DataType, type), "type");
            }

            v.StringValue = stringValue;
        }
Exemple #10
0
        /// <summary>
        /// 试图转换成真实的类型
        /// </summary>
        /// <param name="pdt"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool TryToRealType(this ClientPropertyDataType pdt, out Type type)
        {
            type = typeof(string);

            return(_DataTypeMappings.TryGetValue(pdt, out type));
        }
Exemple #11
0
 public static PropertyDataType ToPropertyDataType(this ClientPropertyDataType cpdt)
 {
     return((PropertyDataType)cpdt);
 }
        public void AddOrSetValue <T>(string key, T value)
        {
            ClientPropertyDataType dataType = typeof(T).ToClientPropertyDataType();

            this.AddOrSetValue(key, dataType, value);
        }
		private void InitFromPropertyDefine(ClientPropertyDefine def)
		{
			ExceptionHelper.FalseThrow<ArgumentNullException>(def != null, "def");

			this._AlterKey = def.Name;
			this._StringValue = def.DefaultValue;
			this._DataType = def.DataType;
			this._StringValue = InitDefaultValue(this._DataType, def.DefaultValue);
		}
		private static string InitDefaultValue(ClientPropertyDataType dataType, string defaultValue)
		{
			string result = defaultValue;

			if (defaultValue.IsNullOrEmpty() && dataType != ClientPropertyDataType.String)
			{
				object data = TypeCreator.GetTypeDefaultValue(dataType.ToRealType());

				if (data != null)
					result = data.ToString();
			}

			return result;
		}