IEnumerable <CustomChildVerbalizer> IVerbalizeExtensionChildren.GetExtensionChildVerbalizations(object parentElement, IVerbalizeFilterChildren filter, VerbalizationSign sign) { // Get the instance data local and release the cached iterator IORMExtendableElement propertyOwner = parentElement as IORMExtendableElement; if (propertyOwner != null) { PropertyDefinitionFilter propertyFilter = myPropertyFilter; LinkedElementCollection <ModelElement> extensions = null; foreach (CustomPropertyDefinition customPropertyDefinition in propertyOwner.Store.ElementDirectory.FindElements <CustomPropertyDefinition>()) { object defaultValue; string defaultValueString; if (!customPropertyDefinition.VerbalizeDefaultValue || null == (defaultValue = customPropertyDefinition.DefaultValue) || (null != (defaultValueString = defaultValue as string) && defaultValueString.Length == 0) || (propertyFilter != null && !propertyFilter(propertyOwner, customPropertyDefinition))) { continue; } bool haveMatchingProperty = false; foreach (ModelElement extensionElement in extensions ?? (extensions = propertyOwner.ExtensionCollection)) { CustomProperty customProperty = extensionElement as CustomProperty; if (customProperty != null && customProperty.CustomPropertyDefinition == customPropertyDefinition) { haveMatchingProperty = true; break; } } if (!haveMatchingProperty) { DefaultPropertyValueVerbalizer verbalizer = DefaultPropertyValueVerbalizer.GetVerbalizer(); verbalizer.Attach(customPropertyDefinition); yield return(CustomChildVerbalizer.VerbalizeInstance(verbalizer, true)); } } } }
/// <summary> /// Create a child verbalizer with the specified delegate filter. /// </summary> /// <param name="filter">A filter used to determine which properties to verbalize</param> public DefaultCustomPropertyVerbalizer(PropertyDefinitionFilter filter) { myPropertyFilter = filter; }