public static ExtensionDeclaration FromXElement(XElement elem, ModuleDeclaration module) { var decl = new ExtensionDeclaration(); decl.Module = module; decl.ExtensionOnTypeName = (string)elem.Attribute("onType"); if (elem.Element("members") != null) { var members = from mem in elem.Element("members").Elements() select Member.FromXElement(mem, module, null) as Member; decl.Members.AddRange(members); foreach (var member in decl.Members) { member.ParentExtension = decl; } } if (elem.Element("inherits") != null) { var inherits = from inherit in elem.Element("inherits").Elements() select SwiftReflector.SwiftXmlReflection.Inheritance.FromXElement(inherit) as Inheritance; decl.Inheritance.AddRange(inherits); } return(decl); }
public static TypeDeclaration TypeFromXElement(XElement elem, ModuleDeclaration module, BaseDeclaration parent /* can be null */) { var decl = FromKind((string)elem.Attribute("kind")); bool isUnrooted = elem.Attribute("module") != null; decl.Module = module; decl.Parent = parent; if (isUnrooted) { decl.IsUnrooted = true; decl.fullUnrootedName = (string)elem.Attribute("name"); decl.unrootedName = decl.fullUnrootedName.NameWithoutModule(); decl.Name = decl.fullUnrootedName.Contains('.') ? decl.fullUnrootedName.Substring(decl.fullUnrootedName.LastIndexOf('.') + 1) : decl.fullUnrootedName; } else { decl.Name = (string)elem.Attribute("name"); } decl.Access = AccessibilityFromString((string)elem.Attribute("accessibility")); decl.IsObjC = elem.BoolAttribute("isObjC"); decl.IsFinal = elem.BoolAttribute("isFinal"); decl.IsDeprecated = elem.BoolAttribute("isDeprecated"); decl.IsUnavailable = elem.BoolAttribute("isUnavailable"); decl.InnerClasses.AddRange(InnerFoo <ClassDeclaration> (elem, "innerclasses", module, decl)); decl.InnerStructs.AddRange(InnerFoo <StructDeclaration> (elem, "innerstructs", module, decl)); decl.InnerEnums.AddRange(InnerFoo <EnumDeclaration> (elem, "innerenums", module, decl)); if (elem.Element("members") != null) { var members = from mem in elem.Element("members").Elements() select Member.FromXElement(mem, module, decl) as Member; decl.Members.AddRange(members); } if (elem.Element("inherits") != null) { var inherits = from inherit in elem.Element("inherits").Elements() select SwiftReflector.SwiftXmlReflection.Inheritance.FromXElement(inherit) as Inheritance; decl.Inheritance.AddRange(inherits); } EnumDeclaration edecl = decl as EnumDeclaration; if (edecl != null) { var enumElements = (from enumElement in elem.Element("elements").Elements() select new EnumElement((string)enumElement.Attribute("name"), (string)enumElement.Attribute("type"), (long?)enumElement.Attribute("intValue"))).ToList();; edecl.Elements.AddRange(enumElements); if (elem.Attribute("rawType") != null) { edecl.RawTypeName = (string)elem.Attribute("rawType"); } } return(decl); }