/// <summary> /// Returns a list of all properties within the classifier. /// Also properties from generalized classes need to be returned /// </summary> /// <param name="classifier"></param> /// <param name="legacy">true, if legacy access to the attributes shall be used. /// This means that the methods are accessed via string definitions and not via the properties</param> /// <returns></returns> public IEnumerable<string> GetPropertiesOfClassifier(IElement classifier) { if (classifier == null) throw new ArgumentNullException(nameof(classifier)); var metaLayer = Legacy ? null : _dataLayerLogic.GetMetaLayerFor(_dataLayerLogic.GetDataLayerOfObject(classifier)); var uml = Legacy ? null : _dataLayerLogic.Get<_UML>(metaLayer); var propertyOwnedAttribute = Legacy ? "ownedAttribute" : _UML._StructuredClassifiers._StructuredClassifier.ownedAttribute; var propertyGeneralization = Legacy ? "generalization" : _UML._Classification._Classifier.generalization; var propertyGeneral = Legacy ? "general" : _UML._Classification._Generalization.general; if (classifier.isSet(propertyOwnedAttribute)) { var result = classifier.get(propertyOwnedAttribute) as IEnumerable; foreach (var item in result) { yield return item.ToString(); } } // Check for generalizations if (classifier.isSet(propertyGeneralization)) { var generalizations = classifier.get(propertyGeneralization) as IEnumerable; foreach (var generalization in generalizations.Cast<IElement>()) { var general = generalization.get(propertyGeneral) as IElement; // Especially for the MOF extent, the generalizations are references in xml and are // filled out by the simple loader if (general != null) { foreach (var found in GetPropertiesOfClassifier(general)) { yield return found; } } } } }
public IElement Copy(IElement element) { var targetElement = _factory.create(element.getMetaClass()); var elementAsExt = element as IObjectAllProperties; if (elementAsExt == null) { throw new ArgumentException("element is not of type IObjectAllProperties"); } foreach (var property in elementAsExt.getPropertiesBeingSet()) { var value = element.get(property); targetElement.set(property, value); } return targetElement; }
public static object GetValue(IElement element, string property, object defaultValue = null) { return element.isSet(property) ? element.get(property) : defaultValue; }