private void ProcessDescriptors(System.ComponentModel.PropertyDescriptor[] descriptors) { foreach (var attributeDesc in descriptors.OfType <AttributePropertyDescriptor>()) { var args = attributeDesc.AttributeInfo.GetTagLocal <PropertyChangedEventArgsCollection>(); if (args == null) { args = new PropertyChangedEventArgsCollection(); attributeDesc.AttributeInfo.SetTag <PropertyChangedEventArgsCollection>(args); } args.Add(new PropertyChangedEventArgs(attributeDesc.DisplayName)); } }
/// <summary> /// Checks all property descriptors of adapter type and when an ObservableDomPropertyAttribute /// is present on the descriptor, finds the AttributeInfo with matching name on the DomNodeType, /// and sets PropertyChangedEventArgs tags to match</summary> /// <param name="adapterType">Type of adapter</param> /// <param name="nodeType">DomNode type</param> private static void AddAttributeTags(Type adapterType, DomNodeType nodeType) { foreach (var property in adapterType.GetProperties()) { object[] attributes = property.GetCustomAttributes(typeof(ObservableDomPropertyAttribute), true); if (attributes != null && attributes.Length > 0) { var eventArgs = new PropertyChangedEventArgs(property.Name); foreach (var attribute in attributes) { var attributeName = ((ObservableDomPropertyAttribute)attribute).AttributeName; var currentType = nodeType; var attributeInfo = currentType.GetAttributeInfo(attributeName); Requires.NotNull(attributeInfo, "Unrecognized attribute name in ObservableDomPropertyAttribute"); // Each base type may have duplicate attributeInfo if it is an inherited attribute // We need to set the tag on each base attributeInfo so that the PropertyChanged event // will be raised even if the attribute is set on a base type while (currentType != DomNodeType.BaseOfAllTypes && attributeInfo != null) { var args = attributeInfo.GetTagLocal <PropertyChangedEventArgsCollection>(); if (args == null) { args = new PropertyChangedEventArgsCollection(); attributeInfo.SetTag(args); } args.Add(eventArgs); currentType = currentType.BaseType; attributeInfo = currentType.GetAttributeInfo(attributeName); } } } } }
private void ProcessDescriptors(System.ComponentModel.PropertyDescriptor[] descriptors) { foreach (var attributeDesc in descriptors.OfType<AttributePropertyDescriptor>()) { var args = attributeDesc.AttributeInfo.GetTagLocal<PropertyChangedEventArgsCollection>(); if (args == null) { args = new PropertyChangedEventArgsCollection(); attributeDesc.AttributeInfo.SetTag<PropertyChangedEventArgsCollection>(args); } args.Add(new PropertyChangedEventArgs(attributeDesc.DisplayName)); } }