/// <summary>
        /// Initialize the specified property in 'graph' given a total list of
        /// available properties in 'allProperties.' Dependency references that
        /// do not exist in 'allProperties' and duplicates are silently ignored.
        /// </summary>
        /// <returns>The initialize.</returns>
        /// <param name="property">Property.</param>
        /// <param name="graph">Graph.</param>
        /// <param name="allProperties">All properties.</param>
        private static PropertyNode Initialize(PropertyInfo property, PropertyGraph graph, IList <PropertyInfo> allProperties)
        {
            PropertyNode node;

            if (graph.ContainsKey(property.Name))
            {
                node = graph[property.Name];
            }
            else
            {
                node = new PropertyNode(property.Name);
                graph[property.Name] = node;
                var dependencyAttr = property.GetCustomAttribute <DependsOnAttribute>();
                if (dependencyAttr == null)
                {
                    return(node);
                }

                foreach (var propName in dependencyAttr.Properties)
                {
                    var dependency = allProperties.FirstOrDefault(p => propName.Equals(p.Name));
                    if (dependency == null)
                    {
                        continue;
                    }

                    var dependencyNode = Initialize(dependency, graph, allProperties);
                    dependencyNode.AddDependent(node);
                }
            }

            return(node);
        }
Exemplo n.º 2
0
 private PropertyModel(INotifyPropertyChanged host, PropertyGraph graph, Action <string> onPropertyChanged)
 {
     this.host                  = host;
     this.graph                 = graph;
     this.onPropertyChanged     = onPropertyChanged;
     this.host.PropertyChanged += this.OnHostPropertyChanged;
 }
        public static PropertyGraph BuildFor(Type type)
        {
            var graph         = new PropertyGraph();
            var allProperties = type.GetRuntimeProperties().ToList();

            foreach (var dependent in allProperties.Where(HasAttribute))
            {
                Initialize(dependent, graph, allProperties);
            }
            return(graph);
        }
Exemplo n.º 4
0
        public static PropertyModel Create(INotifyPropertyChanged host, Action <string> onPropertyChanged)
        {
            var           type = host.GetType();
            PropertyGraph graph;

            if (typeGraphCache.ContainsKey(type))
            {
                graph = typeGraphCache[type];
            }
            else
            {
                graph = PropertyGraph.BuildFor(type);
                typeGraphCache[type] = graph;
            }
            return(new PropertyModel(host, graph, onPropertyChanged));
        }