示例#1
0
        public static T Get <T>(this PropertyReference propertyReference)
        {
            if (propertyReference.getter == null)
            {
                var propertyInfo = propertyReference.GetPropertyInfo();

                propertyReference.getter = PropertyValueGetterUtils.MakeGetter(propertyInfo.PropertyType, propertyReference.target, propertyInfo);
            }

            if (propertyReference.getter == null)
            {
                return(default(T));
            }

            var value = propertyReference.GetValue();

            if (typeof(T) == typeof(string))
            {
                if (value == null)
                {
                    return(default(T));
                }
                return((T)(object)value.ToString());
            }
            if (value is T)
            {
                return((T)value);
            }
            return(default(T));
        }
 protected void Cache <T>()
 {
     PropertyValueGetterUtils.AddTypeByGetter(new ValueGetterCache <T>());
 }