internal PropertyLink(PropertyMonitoringTree monitoringTree, PropertyLink rootward, DeclaredProperty property) { MonitoringTree = monitoringTree; monitoringTree.AllLinks.Add(this); Rootward = rootward; Property = property; TermFromRoot = Term.Append(monitoringTree.Stub, GetTermFromRoot(monitoringTree.OutputTermComponentSeparator), false); HasUnresolvedIndexes = TermFromRoot.OfType <AnyIndexProperty>().Any(); }
/// <summary> /// Creates a new property tree for the given root type /// </summary> /// <param name="rootType">The root type to monitor</param> /// <param name="outputTermComponentSeparator">The component separator to use in output terms</param> /// <param name="stub">The term stub to append all output terms to</param> /// <param name="handleObservedChange">The handler of output terms and new and old values</param> internal PropertyMonitoringTree ( Type rootType, string outputTermComponentSeparator, Term stub, ObservedChangeHandler handleObservedChange, TypeCache typeCache ) { OutputTermComponentSeparator = outputTermComponentSeparator; HandleObservedChange = handleObservedChange; Stub = stub; AllLinks = new HashSet <PropertyLink>(); var discoveredTypes = new HashSet <Type>(); void recurseTree(Type owner, PropertyLink rootWard) { if (!discoveredTypes.Add(owner)) { return; } if (owner.ImplementsGenericInterface(typeof(IEnumerable <>), out var p)) { var elementType = p[0]; var link = new PropertyLink(this, rootWard, new AnyIndexProperty(elementType, owner)); recurseTree(elementType, link); } foreach (var property in typeCache.GetDeclaredProperties(owner).Values) { var link = new PropertyLink(this, rootWard, property); recurseTree(property.Type, link); } } recurseTree(rootType, null); Activate(); }