Beispiel #1
0
        internal static void SetValue(object target, PropertyInfo targetProperty, object value)
        {
            if (value == null)
            {
                if (TypeExpress.AllowNullValue(targetProperty.PropertyType))
                {
                    targetProperty.SetValue(target, null);
                }
                return;
            }
            Type sourceType = value.GetType();
            Type targetType = targetProperty.PropertyType;

            if (sourceType == targetType)
            {
                targetProperty.SetValue(target, value);
                return;
            }
            if (ConvertExpress.CanConvert(sourceType, targetType))
            {
                object convertedValue = ConvertExpress.Convert(value, targetType);
                if (convertedValue == null)
                {
                    if (TypeExpress.AllowNullValue(targetProperty.PropertyType))
                    {
                        targetProperty.SetValue(target, null);
                    }
                }
                else
                {
                    targetProperty.SetValue(target, convertedValue);
                }
            }
        }
Beispiel #2
0
 internal static bool CanSetValue(PropertyInfo sourceProperty, PropertyInfo targetProperty)
 {
     return(ConvertExpress.CanConvert(sourceProperty.PropertyType, targetProperty.PropertyType));
 }