Exemple #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);
        }
Exemple #2
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 #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);
        }