public ToEntity GetModel() { ToEntity Result = new ToEntity(); var AllowNames = ToPropertyNames.Where(o => !ExcludeNames.Contains(o)); foreach (var PropertyName in AllowNames) { if (ToCache.IsListProperty(PropertyName)) { continue; } var StingValue = GetRequest(PropertyName); if (null == StingValue) { continue; } try { Type PropertyType = ToCache.PropertyDic[PropertyName].GetType(); SetPropertyValue(Result, PropertyName, StingValue); FoundNamesCount++; } catch (Exception ex) { x.Say(String.Format("设置属性[{0}]的值为[{1}]时候,出现了异常:{2}", PropertyName, StingValue, ex.Message)); } } return(Result); }
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); }
public void SetPropertyValue(ToEntity target, string propertyName, object newValue) { if (ToCache.IsEnumProperty(propertyName)) { var property = ToCache.PropertyDic[propertyName]; Type PropertyType = EntityTypesCacheItem.GetRealType(property.PropertyType); var EnumValue = System.Enum.Parse(PropertyType, newValue.ToString()); _ToSeter.SetValue(target, propertyName, EnumValue); return; } _ToSeter.SetValue(target, propertyName, newValue); }