Example #1
0
        public void SetPropertyValue(ToEntity target, string propertyName, string strValue)
        {
            var  property     = ToCache.PropertyDic[propertyName];
            Type PropertyType = EntityTypesCacheItem.GetRealType(property.PropertyType);

            if (ToCache.IsEnumProperty(propertyName))
            {
                var EnumValue = System.Enum.Parse(PropertyType, strValue);
                _ToSeter.SetValue(target, propertyName, EnumValue);
                return;
            }
            if (PropertyType == typeof(string))
            {
                _ToSeter.SetValue(target, propertyName, strValue);
                return;
            }
            if (EntityTypesCacheItem.IsNullableType(PropertyType))
            {
                var value = new NullableConverter(PropertyType).ConvertFrom(strValue);
                _ToSeter.SetValue(target, propertyName, value);
                return;
            }
            var SimplyValue = Convert.ChangeType(strValue, PropertyType);

            _ToSeter.SetValue(target, propertyName, SimplyValue);
        }
Example #2
0
        /// <summary>
        /// 根据名称获得属性值
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        private object GetProperty2Sql(T model, string propertyName)
        {
            if (TypeCache.IsListProperty(propertyName))
            {
                x.Say(" 发现了List类型的数据:" + propertyName);
                return(null);
            }
            //if (TypeCache.IsListProperty(propertyName))
            //    return null;
            var    Property = TypeCache.PropertyDic[propertyName];
            Type   PropertyType;
            Type   PropertyTypeReal;
            object PropertyValue = null;

            PropertyType = Property.PropertyType;
            if (TypeCache.IsEnumProperty(propertyName))
            {
                var EnumValue = _PropertyValueGeter.GetValue(model, propertyName);
                x.Say(" 发现了枚举类型的数据:" + propertyName);
                return(Convert.ToInt32(EnumValue));
            }
            if (EntityTypesCacheItem.IsNullableType(PropertyType))
            {
                PropertyValue = _PropertyValueGeter.GetValue(model, propertyName);
                if (null == PropertyValue)
                {
                    return(null);
                }
                PropertyTypeReal = EntityTypesCacheItem.GetRealType(PropertyType);
                //日期时间,加前后引号
                if (typeof(DateTime) == PropertyTypeReal)
                {
                    return("'" + PropertyValue.ToString() + "'");
                }
            }
            //字符串,加前后引号
            if (typeof(String) == PropertyType)
            {
                PropertyValue = _PropertyValueGeter.GetValue(model, propertyName);
                if (null == PropertyValue)
                {
                    return(null);
                }
                if (0 == ((string)PropertyValue).Length)
                {
                    return(null);
                }

                PropertyValue = ((string)PropertyValue).Replace("\'", "\'");
                return("'" + PropertyValue + "'");
            }

            PropertyValue = _PropertyValueGeter.GetValue(model, propertyName);


            return(PropertyValue);
        }