private void addEStructuralFeatures(EObject eobject, XmlNode node) { foreach (XmlAttribute attribute in node.Attributes) { var name = attribute.Name; var estructuralfeature = eobject.eClass().getEStructuralFeature(name); if (estructuralfeature is EAttribute && (estructuralfeature as EAttribute).iD) { var id = attribute.InnerText; registry[id] = eobject; } if (estructuralfeature is EAttribute) { if (!estructuralfeature.many) { var etype = estructuralfeature.eType; var value = attribute.InnerText; if (etype?.ePackage?.nsURI == "http://www.eclipse.org/emf/2002/Ecore") { if (etype.name == "EBigDecimal") { throw new NotImplementedException(); } else if (etype.name == "EBigInteger") { throw new NotImplementedException(); } else if (etype.name == "EBoolean") { eobject.eSet(estructuralfeature, value == "true" ? true : false); } else if (etype.name == "EBooleanObject") { throw new NotImplementedException(); } else if (etype.name == "EByteArray") { throw new NotImplementedException(); } else if (etype.name == "EByteObject") { throw new NotImplementedException(); } else if (etype.name == "EChar") { eobject.eSet(estructuralfeature, value[0]); } else if (etype.name == "ECharacterObject") { throw new NotImplementedException(); } else if (etype.name == "EDateEDiagnosticChain") { throw new NotImplementedException(); } else if (etype.name == "EDiagnosticChain") { throw new NotImplementedException(); } else if (etype.name == "EDouble") { eobject.eSet(estructuralfeature, Double.Parse(value)); } else if (etype.name == "EDoubleObject") { throw new NotImplementedException(); } //EEList //EEnumerator //EFeatureMap //EFeatureMapEntry else if (etype.name == "EFloat") { eobject.eSet(estructuralfeature, Single.Parse(value)); } else if (etype.name == "EFloatObject") { throw new NotImplementedException(); } else if (etype.name == "EInt") { eobject.eSet(estructuralfeature, Int32.Parse(value)); } else if (etype.name == "EIntegerObject") { throw new NotImplementedException(); } //EJavaClass //EJavaObject else if (etype.name == "ELong") { eobject.eSet(estructuralfeature, Int64.Parse(value)); } else if (etype.name == "ELongObject") { throw new NotImplementedException(); } //EMap //EResource //EResourceSet else if (etype.name == "EShort") { eobject.eSet(estructuralfeature, Int16.Parse(value)); } else if (etype.name == "EShortObject") { throw new NotImplementedException(); } else if (etype.name == "EString") { eobject.eSet(estructuralfeature, value); } //ETreeIterator //EInvocationTargetException } else if (etype is EDataType) { var literalvalue = this.factory.createFromString(etype as EDataType, value); eobject.eSet(estructuralfeature, literalvalue); } } else if (estructuralfeature.many) { var y = 3; } else { var x = 2; } } else if (estructuralfeature is EReference) { this.resolve(eobject, estructuralfeature, attribute.InnerText); } } foreach (XmlNode child in node.ChildNodes) { var containment_name = child.Name; var containment = eobject.eClass().getEStructuralFeature(containment_name); if (containment is EReference) { var containment_er = containment as EReference; if (containment_er.containment) { var classifierId2 = containment.eType.name; if (child.Attributes["xsi:type"] != null) { //use xsi:type to declare a more specific type that is declared in EType of the EReference classifierId2 = child.Attributes["xsi:type"]?.InnerText?.Split(':')[1];//TODO there might be more elegant ways } var eclassifier2 = epackage.getEClassifier(classifierId2); if (eclassifier2 is EClass) { if (containment_er.eType.name == "EStringToStringMapEntry") { //new EcoreEMap<string, string> x = new EcoreEMap<string, string>(containment_er.eType as EClass, containment_er.eType.instanceClass, eobject as InternalEObject, containment_er.getFeatureID()); var key = child.Attributes["key"].InnerText; var value = child.Attributes["value"].InnerText; dynamic bla = eobject; //FIXME why is eGet(containment_er) not working? dynamic map = bla.eGet(containment_er); //var map = bla.eGet(containment_er.getFeatureID(), false, false); //var ecoremap = map as EcoreEMap<string, string>; //https://stackoverflow.com/questions/19283349/c-sharp-generics-wildcards map.put(key, value); } else { var eclass2 = eclassifier2 as EClass; var eobject2 = factory.create(eclass2); if (containment_er.many) { addEStructuralFeatures(eobject2, child); var list = (eobject.eGet(containment_er) as IEnumerable <EObject>).ToList(); list.Add(eobject2); eobject.eSet(containment_er, list); } else { addEStructuralFeatures(eobject2, child); eobject.eSet(containment_er, eobject2); } } } } else { //TODO error } } else { //TODO error } } }
private void addEStructuralFeatures(EObject eobject, XmlNode node) { foreach (XmlAttribute attribute in node.Attributes) { var name = attribute.Name; var estructuralfeature = eobject.eClass().getEStructuralFeature(name); if (estructuralfeature is EAttribute) { if (!estructuralfeature.many) { var etype = estructuralfeature.eType; var value = attribute.InnerText; if (etype?.ePackage?.nsURI == "http://www.eclipse.org/emf/2002/Ecore") { if (etype.name == "EBoolean") { eobject.eSet(estructuralfeature, value == "true" ? true : false); } else if (etype.name == "EInt") { eobject.eSet(estructuralfeature, Int32.Parse(value)); } else if (etype.name == "EString") { eobject.eSet(estructuralfeature, value); } } } else if (estructuralfeature.many) { } } else if (estructuralfeature is EReference) { resolveJobs.Add(new Tuple <EObject, EStructuralFeature, String>(eobject, estructuralfeature, attribute.InnerText)); } } foreach (XmlNode child in node.ChildNodes) { var containment_name = child.Name; var containment = eobject.eClass().getEStructuralFeature(containment_name); if (containment is EReference) { var containment_er = containment as EReference; if (containment_er.containment) { var classifierId2 = containment.eType.name; if (child.Attributes["xsi:type"] != null) { //use xsi:type to declare a more specific type that is declared in EType of the EReference classifierId2 = child.Attributes["xsi:type"]?.InnerText?.Split(':')[1];//TODO there might be more elegant ways } var eclassifier2 = epackage.getEClassifier(classifierId2); if (eclassifier2 is EClass) { if (containment_er.eType.name == "EStringToStringMapEntry") { //new EcoreEMap<string, string> x = new EcoreEMap<string, string>(containment_er.eType as EClass, containment_er.eType.instanceClass, eobject as InternalEObject, containment_er.getFeatureID()); var key = child.Attributes["key"].InnerText; var value = child.Attributes["value"].InnerText; dynamic bla = eobject; //FIXME why is eGet(containment_er) not working? dynamic map = bla.eGet(containment_er); //var map = bla.eGet(containment_er.getFeatureID(), false, false); //var ecoremap = map as EcoreEMap<string, string>; //https://stackoverflow.com/questions/19283349/c-sharp-generics-wildcards map.put(key, value); } else { var eclass2 = eclassifier2 as EClass; var eobject2 = factory.create(eclass2); if (containment_er.many) { addEStructuralFeatures(eobject2, child); var list = new List <EObject>(); list.Add(eobject2); eobject.eSet(containment_er, list); } else { addEStructuralFeatures(eobject2, child); eobject.eSet(containment_er, eobject2); } } } } else { //TODO error } } else { //TODO error } } }