public static TResult Get <TEntity, TResult>(this FlatDataWrapper <TEntity> wrapper, Enum valueName, FlattenDataProvider <TEntity> provider)
            where TEntity : class
        {
            var value = wrapper.Get(valueName, typeof(TResult), provider);

            return(value != null ? (TResult)value : default(TResult));
        }
        public static TResult Get <TEntity, TAttribute, TResult>(this FlatDataWrapper <TEntity> wrapper)
            where TEntity : class
            where TAttribute : Attribute, IEnumType
            where TResult : class, new()
        {
            var result = new TResult();

            foreach (var propertyInfo in result.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var valueTypeAttribute = propertyInfo.GetCustomAttribute <TAttribute>();
                var valueType          = valueTypeAttribute.Type;
                var value = wrapper.Get(valueType, propertyInfo.PropertyType);

                propertyInfo.SetValue(result, value);
            }

            return(result);
        }
Example #3
0
 public static object GetValueFromType <T>(this FlatDataWrapper <T> wrapper, Enum valueName, FlattenDataProvider <T> provider) where T : class
 {
     return(wrapper.Get(valueName, valueName.GetValueType(), provider));
 }