Example #1
0
        // Filter //
        public static IObservableFilter <T> Filter <T>(NotifyConfiguratorFactory <TClass, ObservableFilterPropertyHolder <T> > configurator, [CallerMemberName] string name = null)
        {
            var c = PropertyCache <TClass> .GetByHolder <ObservableFilterPropertyHolder <T> >(name,
                                                                                              n => configurator(new NotifyConfigurator <TClass, ObservableFilterPropertyHolder <T> >().Init((target, filter) => filter.OnTriggered()))
                                                                                              .Compile(n));

            return(new ObservableFilterPropertyHolder <T>(c));
        }
Example #2
0
        // TRIGGER
        public static ITrigger Trigger(NotifyConfiguratorFactory <TClass, NotifyTrigger> configurator, [CallerMemberName] string name = null)
        {
            var c =
                PropertyCache <TClass> .GetByHolder <NotifyTrigger>(name,
                                                                    n => configurator(new NotifyConfigurator <TClass, NotifyTrigger>())
                                                                    .Compile(n)
                                                                    );

            return(new NotifyTrigger(c));
        }
Example #3
0
        /***********
        * COMMAND *
        ***********/
        public static ICommand Command(NotifyConfiguratorFactory <TClass, CommandPropertyHolder> configurator, [CallerMemberName] string name = null)
        {
#if DEBUG
            Debug.Assert(typeof(TClass).GetProperty(name) != null, $"{name} is not a property of " + typeof(TClass).Name + " (did you forget {get;} ?)");
#endif
            var c = PropertyCache <TClass> .GetByHolder <CommandPropertyHolder>(name,
                                                                                n => configurator(new NotifyConfigurator <TClass, CommandPropertyHolder>())
                                                                                .Compile(n));

            return(new CommandPropertyHolder(c));
        }
Example #4
0
        public static PropertyHolder <T> Property <T>(NotifyConfiguratorFactory <TClass, PropertyHolder <T> > configurator, [CallerMemberName] string name = null)
        {
            // TODO : benchmark this and see if just storing uncompiled whould perform better :
            var activator =
                PropertyCache <TClass> .GetByHolder <PropertyHolder <T> >(name,
                                                                          n => configurator(new NotifyConfigurator <TClass, PropertyHolder <T> >())
                                                                          .Compile(n)
                                                                          );

            return(new PropertyHolder <T>(activator));
        }
Example #5
0
        private static bool CheckDependencies(Todo todo, ICollection <string> done, Queue <Todo> todoQueue)
        {
            var a = PropertyCache <TClass> .GetByHolder(todo.MemberInfo.Name);

//            var p = todo.ConfiguratorEntry;
            if (a.DependsOn
                .Where(d => !done.Contains(d))
                .Any(d => todoQueue.Any(i => i.Name == d))
                )
            {
                todoQueue.Enqueue(todo);
                return(false);
            }
            done.Add(a.PropertyName);
            return(true);
        }
Example #6
0
        private static Action <TClass> CreateActivatorA()
        {
            var todoList = new Queue <Todo>();
            var done     = new List <string>();

            var type = typeof(TClass);

            while (true)

            {
                //                var getByHolder = typeof(PropertyCache<>).MakeGenericType(type).GetMethod("GetByHolder",new []{typeof(string)});

                foreach (var mi in type.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Instance |
                                                   BindingFlags.NonPublic | BindingFlags.Public))
                {
                    switch (mi)
                    {
                    case FieldInfo fieldInfo:
                        if (!typeof(IChildObject).IsAssignableFrom(fieldInfo.FieldType))
                        {
                            continue;
                        }
                        if (mi.Name.Contains("k__BackingField"))
                        {
                            continue;
                        }
                        var a = PropertyCache <TClass> .GetByHolder(mi.Name);

                        //var p = (ConfiguratorEntry) getByHolder.Invoke(null,new object[]{mi.Name});
                        todoList.Enqueue(new Todo {
                            MemberInfo = mi, Name = a.PropertyName, Activator = a
                        });
                        break;

                    case PropertyInfo propertyInfo:
                        //if (propertyInfo.CanWrite) continue;
                        if (propertyInfo.GetMethod.IsAbstract)
                        {
                            continue;
                        }

                        if (typeof(IChildObject).IsAssignableFrom(propertyInfo.PropertyType))
                        {
                            todoList.Enqueue(new Todo {
                                MemberInfo = mi, Name = mi.Name
                            });
                        }
                        else if (typeof(ICommand).IsAssignableFrom(propertyInfo.PropertyType))
                        {
                            todoList.Enqueue(new Todo {
                                MemberInfo = mi, Name = mi.Name
                            });
                        }
                        break;
                    }
                }

                type = type.BaseType;
                if (type != null && typeof(INotifyPropertyChangedWithHelper).IsAssignableFrom(type))
                {
                    var t  = typeof(H <>);
                    var t1 = t.MakeGenericType(type);
                    var p  = t1.GetProperty("HasActivator", BindingFlags.NonPublic | BindingFlags.Static);

                    if (p != null)
                    {
                        var hasActivator = (bool)p.GetValue(null);

                        if (hasActivator)
                        {
                            break;
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    break;
                }
            }

            Action <TClass> activator = null;

            while (todoList.TryDequeue(out var todo))
            {
                switch (todo.MemberInfo)
                {
                case FieldInfo fieldInfo:
                    if (!typeof(IChildObject).IsAssignableFrom(fieldInfo.FieldType))
                    {
                        continue;
                    }
                    if (!CheckDependencies(todo, done, todoList))
                    {
                        continue;
                    }
                    activator += t =>
                    {
                        ((IChildObject)fieldInfo.GetValue(t))
                        .Parent = t;
                    };
                    break;

                case PropertyInfo propertyInfo:
                    if (propertyInfo.CanWrite)
                    {
                        continue;
                    }

                    if (typeof(IChildObject).IsAssignableFrom(propertyInfo.PropertyType))
                    {
                        if (!CheckDependencies(todo, done, todoList))
                        {
                            continue;
                        }
                        activator += t =>
                        {
                            var pi    = propertyInfo;
                            var value = propertyInfo.GetValue(t);
                            if (value is IChildObject child)
                            {
                                child.Parent = t;
                            }
                            else
                            {
                            }
                        };
                    }
                    else if (typeof(ICommand).IsAssignableFrom(propertyInfo.PropertyType))
                    {
                        if (!CheckDependencies(todo, done, todoList))
                        {
                            continue;
                        }
                        activator += t =>
                        {
                            if (propertyInfo.GetValue(t) is IChildObject child)
                            {
                                child.Parent = t;
                            }
                        };
                    }
                    break;
                }
            }
            return(activator);
        }