public static MetadataEntityBuilder <T> Disable <T>(this MetadataEntityBuilder <T> builder, Expression <Func <T, object> > expression)
 {
     return(builder.AddAction(store =>
     {
         List <string> disabled = null;
         if (store.TryGetValue(Key, out var disabledObject))
         {
             disabled = disabledObject as List <string>;
         }
         if (disabled == null)
         {
             disabled = new List <string>();
             store[Key] = disabled;
         }
         disabled.Add(ExpressionUtils.GetPropertyName(expression.Body));
     }));
 }
 public static MetadataEntityBuilder <T> Index <T>(this MetadataEntityBuilder <T> builder,
                                                   Expression <Func <T, object> > expression, int index)
 {
     return(builder.AddAction(store =>
     {
         Dictionary <string, int> indexDict = null;
         if (store.TryGetValue(Key, out var indexDictObject))
         {
             indexDict = indexDictObject as Dictionary <string, int>;
         }
         if (indexDict == null)
         {
             indexDict = new Dictionary <string, int>();
             store[Key] = indexDict;
         }
         indexDict.Add(ExpressionUtils.GetPropertyName(expression.Body), index);
     }));
 }
Esempio n. 3
0
        public MetadataBuilder UpdateEntity <T>(Action <MetadataEntityBuilder <T> > action = null)
        {
            actions.Add(store =>
            {
                if (!store.TryGetValue(typeof(T), out var typeData))
                {
                    throw new Exception($"{ typeof(T).FullName } was not registered yet");
                }

                var entityBuilder = new MetadataEntityBuilder <T>();
                if (action != null)
                {
                    action(entityBuilder);
                }
                entityBuilder.ApplyTo(typeData);
            });

            return(this);
        }
Esempio n. 4
0
        public MetadataBuilder RegisterEntity <T>(Action <MetadataEntityBuilder <T> > action = null)
        {
            actions.Add((store) =>
            {
                if (store.ContainsKey(typeof(T)))
                {
                    throw new Exception($"{ typeof(T).FullName } already registered");
                }

                var typeData = new MetaEntityStore();
                store.Add(typeof(T), typeData);

                var entityBuilder = new MetadataEntityBuilder <T>();
                if (action != null)
                {
                    action(entityBuilder);
                }
                entityBuilder.ApplyTo(typeData);
            });

            return(this);
        }
Esempio n. 5
0
 public static MetadataEntityBuilder <T> IsGood <T>(this MetadataEntityBuilder <T> builder, bool isGood = true)
 {
     return(builder.AddAction(store => store[Key] = isGood));
 }