/// <summary> /// Process elements for each FactTypeHasRole definition added /// during deserialization. If one of our extension elements is not /// included in the set of extension elements then create a new one /// and add it. /// </summary> /// <param name="element">A Role element</param> /// <param name="store">The context store</param> /// <param name="notifyAdded">The listener to notify if elements are added during fixup</param> protected sealed override void ProcessElement(Role element, Store store, INotifyElementAdded notifyAdded) { IORMExtendableElement extendableElement = element as IORMExtendableElement; LinkedElementCollection <ModelElement> extensions = extendableElement.ExtensionCollection; int extensionCount = extensions.Count; int i; for (i = 0; i < extensionCount; ++i) { // Look for any of our extension elements if (extensions[i] is MyCustomExtensionElement) { break; } } if (i == extensionCount) { MyCustomExtensionElement customElement = new MyCustomExtensionElement(store); ExtensionElementUtility.AddExtensionElement(extendableElement, customElement); // Always notify during deserialization. All rules are turned off, so // any additions need to be explicitly notified so that other deserialization // fixup listeners can respond appropriately. notifyAdded.ElementAdded(customElement, true); } }
/// <summary> /// Adds the properties from the extension <see cref="ModelElement"/>s of the /// <see cref="IORMExtendableElement"/> specified by <paramref name="extendableElement"/> /// to the <see cref="PropertyDescriptorCollection"/> specified by <paramref name="properties"/>. /// </summary> /// <param name="extendableElement">The <see cref="IORMExtendableElement"/> from which the extension properties should be retrieved.</param> /// <param name="properties">The <see cref="PropertyDescriptorCollection"/> to which the extension properties should be added.</param> /// <param name="displayedWithComponentType">The <see cref="Type"/> of the element the extensions will be displayed with.</param> public static void GetExtensionProperties(IORMExtendableElement extendableElement, PropertyDescriptorCollection properties, Type displayedWithComponentType) { if (extendableElement == null) { throw new ArgumentNullException("extendableElement"); } if (properties == null) { throw new ArgumentNullException("properties"); } foreach (ModelElement extension in extendableElement.ExtensionCollection) { IORMPropertyExtension customPropertyExtension = extension as IORMPropertyExtension; ORMExtensionPropertySettings settings = (customPropertyExtension != null) ? customPropertyExtension.ExtensionPropertySettings : ORMExtensionPropertySettings.MergeAsTopLevelProperty; if (0 != (settings & ORMExtensionPropertySettings.MergeAsExpandableProperty)) { PropertyDescriptor descriptor = ExpandableExtensionPropertyDescriptor.CreateExtensionDescriptor(customPropertyExtension); properties.Add(displayedWithComponentType != null ? EditorUtility.RedirectPropertyDescriptor(extension, descriptor, displayedWithComponentType) : descriptor); } if (0 != (settings & ORMExtensionPropertySettings.MergeAsTopLevelProperty)) { foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(extension)) { properties.Add(displayedWithComponentType != null ? EditorUtility.RedirectPropertyDescriptor(extension, descriptor, displayedWithComponentType) : descriptor); } } } }
/// <summary> /// Adds the extension <see cref="ModelError"/> specified by <paramref name="extensionError"/> to the /// <see cref="IORMExtendableElement"/> specified by <paramref name="extendedElement"/>. /// </summary> public static void AddExtensionModelError(IORMExtendableElement extendedElement, ModelError extensionError) { if (extendedElement == null) { throw new ArgumentNullException("extendedElement"); } if (extensionError == null) { throw new ArgumentNullException("extensionError"); } extendedElement.ExtensionModelErrorCollection.Add(extensionError); }
private CustomProperty FindCustomProperty(IORMExtendableElement modelElement) { if (modelElement != null) { foreach (ModelElement extensionElement in modelElement.ExtensionCollection) { CustomProperty customProperty = extensionElement as CustomProperty; if (customProperty != null && customProperty.CustomPropertyDefinition == this.customPropertyDefinition) { return(customProperty); } } } return(null); }
IORMExtendableElement IORMExtendableElementService.ResolveExtendedErrorOwner(ModelError extensionError) { List <Guid> errorRoles = myExtensionErrorRoles; IORMExtendableElement retVal = null; if (errorRoles != null) { for (int i = 0, count = errorRoles.Count; i < count; ++i) { if (null != (retVal = DomainRoleInfo.GetLinkedElement(extensionError, errorRoles[i]) as IORMExtendableElement)) { break; } } } return(retVal); }
/// <summary> /// Adds the extension <see cref="ModelElement"/> specified by <paramref name="extensionElement"/> to the /// <see cref="IORMExtendableElement"/> specified by <paramref name="extendedElement"/>. /// </summary> public static void AddExtensionElement(IORMExtendableElement extendedElement, ModelElement extensionElement) { if (extendedElement == null) { throw new ArgumentNullException("extendedElement"); } if (extensionElement == null) { throw new ArgumentNullException("extensionElement"); } LinkedElementCollection <ModelElement> extensions = extendedElement.ExtensionCollection; if (extensions != null) { extensions.Add(extensionElement); } }
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)); } } } }