Exemple #1
0
        internal static object GetByKey <T>(this FlatDataWrapper <T> wrapper, string key, Type type) where T : class
        {
            var jobj  = wrapper.JObject;
            var value = jobj[key];

            return(value?.ToObject(type));
        }
        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 void Set <TEntity, TEnum, TValue>(this FlatDataWrapper <TEntity> wrapper, TEnum valueName, TValue valueType)
            where TEntity : class
        {
            valueName.CheckValueType <TEnum, TValue>();
            string key = valueName.ToString();

            wrapper.SetValue(key, valueType);
        }
        public FlatDataWrapper <TEntity> GetParentWrapper(FlatDataWrapper <TEntity> wrapper)
        {
            if (!cache.ContainsKey(wrapper.Parent))
            {
                cache[wrapper.Parent] = wrapper.ParentWrapper;
            }

            return(cache[wrapper.Parent]);
        }
        public static void Set <TEntity, TEnum>(this FlatDataWrapper <TEntity> wrapper, string name, JToken value)
            where TEntity : class
            where TEnum : struct, IConvertible
        {
            TEnum valueName = GetValueName <TEnum>(name);
            Type  valueType = valueName.GetAttributeOfType <TEnum, TypeConstraintAttribute>().ValueType;

            wrapper.Set(valueName, value, valueType);
        }
Exemple #6
0
        internal static object GetFromParent <T>(
            this FlatDataWrapper <T> wrapper,
            Enum settingType,
            Type type,
            FlattenDataProvider <T> provider)
            where T : class
        {
            var parentWrapper = provider != null
                ? provider.GetParentWrapper(wrapper)
                : wrapper.ParentWrapper;

            return(parentWrapper.Get(settingType, type, provider));
        }
        public static void Set <TEntity, TAttribute, TResult>(this FlatDataWrapper <TEntity> wrapper, TResult model)
            where TEntity : class
            where TAttribute : Attribute, IEnumType
            where TResult : class, new()
        {
            foreach (var propertyInfo in model.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var valueTypeAttribute = propertyInfo.GetCustomAttribute <TAttribute>();
                var valueType          = valueTypeAttribute.Type;

                valueType.CheckValueType(propertyInfo.PropertyType);
                string key = valueType.ToString();

                wrapper.SetValue(key, propertyInfo.GetValue(model));
            }
        }
        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);
        }
Exemple #9
0
        internal static void SetValue <T>(this FlatDataWrapper <T> wrapper, string key, object value) where T : class
        {
            JObject jobj;

            if (!string.IsNullOrEmpty(wrapper.Data))
            {
                jobj = JObject.Parse(wrapper.Data);
                jobj.Remove(key);
            }
            else
            {
                jobj = new JObject();
            }

            if (value != null)
            {
                jobj[key] = JToken.FromObject(value);
                wrapper.Entity.SetPropertyValue(wrapper.PropertyLambda, jobj.ToString());
            }
        }
Exemple #10
0
        public static IEnumerable <TEnum> FilterRelatedTypes <TEntity, TEnum>(this FlatDataWrapper <TEntity> wrapper) where TEntity : class
        {
            var allValues = Enum.GetValues(typeof(TEnum)).Cast <Enum>();

            return(allValues.Where(value => value.RelatedToTypeOfEntity(wrapper.Entity)).Cast <TEnum>());
        }
Exemple #11
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));
 }
Exemple #12
0
 internal static FlatDataWrapper <T> GetWrapperForParent <T>(this FlatDataWrapper <T> wrapper) where T : class
 {
     return(new FlatDataWrapper <T>(wrapper.Parent, wrapper.PropertyLambda, wrapper.ParentLambda));
 }