Exemple #1
0
        /// <summary>
        /// 进行克隆的方法
        /// </summary>
        /// <param name="source">克隆的来源</param>
        /// <returns>克隆出来的新对象</returns>
        public Entity Clone(Entity source)
        {
            if (null == source)
            {
                return(null);
            }
            Entity Result = new Entity();

            List <string> CloneNames = PropertyNames.Except(ExcludeNames).ToList();

            foreach (string PropertyName in CloneNames)
            {
                if (PropertyNames.Exists(o => o == PropertyName))
                {
                    _Copyer.SetValue(Result, PropertyName, _Copyer.GetValue(source, PropertyName));
                }
            }
            return(Result);
        }
Exemple #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);
        }
Exemple #3
0
        public ToEntity CopyEntity(FromEntity source)
        {
            if (null == source)
            {
                return(null);
            }
            ToEntity Result = new ToEntity();

            foreach (string PropertyName in FromPropertyNames)
            {
                if (ToPropertyNames.Exists(o => o == PropertyName))
                {
                    _ToSeter.SetValue(Result, PropertyName, _FromGeter.GetValue(source, PropertyName));
                }
            }



            return(Result);
        }