public Init ( |
||
element | ||
return | void |
internal void ElementsToTypes() { bool isRoot = false; int rootElementsCount = schemas.GlobalElements.Count; foreach (XmlSchemaElement elem in schemas.GlobalElements.Values) { SymbolEntry symbol = symbolTable.AddElement(elem); XmlSchemaType schemaType = elem.ElementSchemaType; string xsdNamespace = elem.QualifiedName.Namespace; ClrTypeInfo typeInfo = null; XmlSchemaElement headElement = null; if (!elem.SubstitutionGroup.IsEmpty) { headElement = (XmlSchemaElement)schemas.GlobalElements[elem.SubstitutionGroup]; } if (schemaType.IsGlobal()) { //Global elem with global type, generate wrapper class for the element bool hasBaseContentType = headElement != null && headElement.ElementSchemaType == schemaType; ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo(hasBaseContentType); ClrTypeReference typeDef = BuildTypeReference(schemaType, schemaType.QualifiedName, false, true); //Save the fixed/default value of the element wtypeInfo.InnerType = typeDef; typeInfo = wtypeInfo; typeInfo.baseType = headElement; //If element is member of substitutionGroup, add derivation step } else { ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo(); localSymbolTable.Init(symbol.identifierName); ctypeInfo.baseType = headElement; //If element is member of substitutionGroup, add derivation step BuildProperties(elem, schemaType, ctypeInfo); BuildNestedTypes(ctypeInfo); typeInfo = ctypeInfo; } if (!isRoot) { if (rootElementsCount == 1 || CheckUnhandledAttributes(elem)) { typeInfo.IsRoot = true; isRoot = true; } } typeInfo.IsSubstitutionHead = IsSubstitutionGroupHead(elem) != null; typeInfo.IsAbstract = elem.IsAbstract; typeInfo.clrtypeName = symbol.identifierName; typeInfo.clrtypeNs = symbol.clrNamespace; typeInfo.schemaName = symbol.symbolName; typeInfo.schemaNs = xsdNamespace; typeInfo.typeOrigin = SchemaOrigin.Element; BuildAnnotationInformation(typeInfo, schemaType); binding.Types.Add(typeInfo); } }
private void CreateXRoot(CodeNamespace codeNamespace, string rootName, List <CodeTypeDeclaration> elements, List <CodeNamespace> namespaces, GeneratedTypesVisibility visibility = GeneratedTypesVisibility.Public) { LocalSymbolTable lst = new LocalSymbolTable(); CodeTypeDeclaration xroot = CodeDomHelper.CreateTypeDeclaration(rootName, null, visibility); //Create Methods CodeMemberField docField = CodeDomHelper.CreateMemberField("doc", "XDocument", false, MemberAttributes.Private); CodeMemberField rootField = CodeDomHelper.CreateMemberField("rootObject", Constants.XTypedElement, false, MemberAttributes.Private); xroot.Members.Add(docField); xroot.Members.Add(rootField); lst.Init(rootName); lst.RegisterMember("doc"); lst.RegisterMember("rootObject"); lst.RegisterMember("Load"); lst.RegisterMember("Parse"); lst.RegisterMember("Save"); lst.RegisterMember("XDocument"); lst.RegisterMember("Root"); // Constructor xroot.Members.Add(CodeDomHelper.CreateConstructor(MemberAttributes.Private)); //Load Methods xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "System.String", "xmlFile" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "System.String", "xmlFile" }, new string[] { "LoadOptions", "options" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "TextReader", "textReader" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "TextReader", "textReader" }, new string[] { "LoadOptions", "options" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "XmlReader", "xmlReader" } }, visibility)); //Parse Methods xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Parse", new string[][] { new string[] { "System.String", "text" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Parse", new string[][] { new string[] { "System.String", "text" }, new string[] { "LoadOptions", "options" } }, visibility)); //Save Methods xroot.Members.Add( CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "System.String", "fileName" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "TextWriter", "textWriter" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "XmlWriter", "writer" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "TextWriter", "textWriter" }, new string[] { "SaveOptions", "options" } }, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "System.String", "fileName" }, new string[] { "SaveOptions", "options" } }, visibility)); CodeMemberProperty docProp = CodeDomHelper.CreateProperty("XDocument", "XDocument", docField, visibility.ToMemberAttribute(), false); xroot.Members.Add(docProp); CodeMemberProperty rootProp = CodeDomHelper.CreateProperty("Root", "XTypedElement", rootField, visibility.ToMemberAttribute(), false); xroot.Members.Add(rootProp); for (int i = 0; i < elements.Count; i++) { string typeName = elements[i].Name; string fqTypeName = (namespaces == null || namespaces[i].Name == String.Empty) ? typeName : "global::" + namespaces[i].Name + "." + typeName; xroot.Members.Add(CodeDomHelper.CreateXRootFunctionalConstructor(fqTypeName, visibility)); xroot.Members.Add(CodeDomHelper.CreateXRootGetter(typeName, fqTypeName, lst, visibility)); } codeNamespace.Types.Add(xroot); }
private void CreateXRoot( CodeNamespace codeNamespace, string rootName, List<CodeTypeDeclaration> elements, List<CodeNamespace> namespaces) { if (codeNamespace != null) { LocalSymbolTable lst = new LocalSymbolTable(this.settings); CodeTypeDeclaration xroot = CodeDomHelper.CreateTypeDeclaration(rootName, null); //Create Methods CodeMemberField docField = CodeDomHelper.CreateMemberField("doc", "XDocument", MemberAttributes.Private, false); CodeMemberField rootField = CodeDomHelper.CreateMemberField("rootObject", Constants.XTypedElement, MemberAttributes.Private, false); xroot.Members.Add(docField); xroot.Members.Add(rootField); lst.Init(rootName); lst.RegisterMember("doc"); lst.RegisterMember("rootObject"); lst.RegisterMember("Load"); lst.RegisterMember("Parse"); lst.RegisterMember("Save"); lst.RegisterMember("XDocument"); // Constructor xroot.Members.Add(CodeDomHelper.CreateConstructor(MemberAttributes.Private)); //Load Methods xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "System.String", "xmlFile" } })); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][]{new string[]{"System.String", "xmlFile"}, new string[]{"LoadOptions", "options"}})); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "TextReader", "textReader" } })); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][]{new string[]{"TextReader", "textReader"}, new string[]{"LoadOptions", "options"}})); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", new string[][] { new string[] { "XmlReader", "xmlReader" } })); //Parse Methods xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Parse", new string[][] { new string[] { "System.String", "text" } })); xroot.Members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Parse", new string[][]{new string[]{"System.String", "text"}, new string[]{"LoadOptions", "options"}})); //Save Methods xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "System.String", "fileName" } })); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "TextWriter", "textWriter" } })); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][] { new string[] { "XmlWriter", "writer" } })); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][]{new string[]{"TextWriter", "textWriter"}, new string[]{"SaveOptions", "options"}})); xroot.Members.Add(CodeDomHelper.CreateXRootSave(new string[][]{new string[]{"System.String", "fileName"}, new string[]{"SaveOptions", "options"}})); CodeMemberProperty prop = CodeDomHelper.CreateProperty("XDocument", "XDocument", docField, MemberAttributes.Public, false); xroot.Members.Add(prop); for (int i = 0; i < elements.Count; i++) { string typeName = elements[i].Name; string fqTypeName = (namespaces == null || namespaces[i].Name == String.Empty) ? typeName : "global::" + namespaces[i].Name + "." + typeName; xroot.Members.Add(CodeDomHelper.CreateXRootFunctionalConstructor(fqTypeName)); xroot.Members.Add(CodeDomHelper.CreateXRootGetter(typeName, fqTypeName, lst)); } codeNamespace.Types.Add(xroot); } }
private void CreateXRoot(CodeNamespace codeNamespace, string rootName, List <CodeTypeDeclaration> elements, List <CodeNamespace> namespaces) { if (codeNamespace != null) { LocalSymbolTable lst = new LocalSymbolTable(this.settings); CodeTypeDeclaration xroot = CodeDomHelper.CreateTypeDeclaration(rootName, null); CodeMemberField docField = CodeDomHelper.CreateMemberField("doc", "XDocument", MemberAttributes.Private, false); CodeMemberField rootField = CodeDomHelper.CreateMemberField("rootObject", "XTypedElement", MemberAttributes.Private, false); xroot.Members.Add(docField); xroot.Members.Add(rootField); lst.Init(rootName); lst.RegisterMember("doc"); lst.RegisterMember("rootObject"); lst.RegisterMember("Load"); lst.RegisterMember("Parse"); lst.RegisterMember("Save"); lst.RegisterMember("XDocument"); xroot.Members.Add(CodeDomHelper.CreateConstructor(MemberAttributes.Private)); CodeTypeMemberCollection members = xroot.Members; string[][] strArrays = new string[1][]; string[] strArrays1 = new string[] { "System.String", "xmlFile" }; strArrays[0] = strArrays1; members.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", strArrays)); CodeTypeMemberCollection codeTypeMemberCollection = xroot.Members; strArrays = new string[2][]; strArrays1 = new string[] { "System.String", "xmlFile" }; strArrays[0] = strArrays1; strArrays1 = new string[] { "LoadOptions", "options" }; strArrays[1] = strArrays1; codeTypeMemberCollection.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", strArrays)); CodeTypeMemberCollection members1 = xroot.Members; strArrays = new string[1][]; strArrays1 = new string[] { "TextReader", "textReader" }; strArrays[0] = strArrays1; members1.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", strArrays)); CodeTypeMemberCollection codeTypeMemberCollection1 = xroot.Members; strArrays = new string[2][]; strArrays1 = new string[] { "TextReader", "textReader" }; strArrays[0] = strArrays1; strArrays1 = new string[] { "LoadOptions", "options" }; strArrays[1] = strArrays1; codeTypeMemberCollection1.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", strArrays)); CodeTypeMemberCollection members2 = xroot.Members; strArrays = new string[1][]; strArrays1 = new string[] { "XmlReader", "xmlReader" }; strArrays[0] = strArrays1; members2.Add(CodeDomHelper.CreateXRootMethod(rootName, "Load", strArrays)); CodeTypeMemberCollection codeTypeMemberCollection2 = xroot.Members; strArrays = new string[1][]; strArrays1 = new string[] { "System.String", "text" }; strArrays[0] = strArrays1; codeTypeMemberCollection2.Add(CodeDomHelper.CreateXRootMethod(rootName, "Parse", strArrays)); CodeTypeMemberCollection members3 = xroot.Members; strArrays = new string[2][]; strArrays1 = new string[] { "System.String", "text" }; strArrays[0] = strArrays1; strArrays1 = new string[] { "LoadOptions", "options" }; strArrays[1] = strArrays1; members3.Add(CodeDomHelper.CreateXRootMethod(rootName, "Parse", strArrays)); CodeTypeMemberCollection codeTypeMemberCollection3 = xroot.Members; strArrays = new string[1][]; strArrays1 = new string[] { "System.String", "fileName" }; strArrays[0] = strArrays1; codeTypeMemberCollection3.Add(CodeDomHelper.CreateXRootSave(strArrays)); CodeTypeMemberCollection members4 = xroot.Members; strArrays = new string[1][]; strArrays1 = new string[] { "TextWriter", "textWriter" }; strArrays[0] = strArrays1; members4.Add(CodeDomHelper.CreateXRootSave(strArrays)); CodeTypeMemberCollection codeTypeMemberCollection4 = xroot.Members; strArrays = new string[1][]; strArrays1 = new string[] { "XmlWriter", "writer" }; strArrays[0] = strArrays1; codeTypeMemberCollection4.Add(CodeDomHelper.CreateXRootSave(strArrays)); CodeTypeMemberCollection members5 = xroot.Members; strArrays = new string[2][]; strArrays1 = new string[] { "TextWriter", "textWriter" }; strArrays[0] = strArrays1; strArrays1 = new string[] { "SaveOptions", "options" }; strArrays[1] = strArrays1; members5.Add(CodeDomHelper.CreateXRootSave(strArrays)); CodeTypeMemberCollection codeTypeMemberCollection5 = xroot.Members; strArrays = new string[2][]; strArrays1 = new string[] { "System.String", "fileName" }; strArrays[0] = strArrays1; strArrays1 = new string[] { "SaveOptions", "options" }; strArrays[1] = strArrays1; codeTypeMemberCollection5.Add(CodeDomHelper.CreateXRootSave(strArrays)); CodeMemberProperty prop = CodeDomHelper.CreateProperty("XDocument", "XDocument", docField, MemberAttributes.Public, false); xroot.Members.Add(prop); for (int i = 0; i < elements.Count; i++) { string typeName = elements[i].Name; string fqTypeName = (namespaces == null || namespaces[i].Name == string.Empty ? typeName : string.Concat("global::", namespaces[i].Name, ".", typeName)); xroot.Members.Add(CodeDomHelper.CreateXRootFunctionalConstructor(fqTypeName)); xroot.Members.Add(CodeDomHelper.CreateXRootGetter(typeName, fqTypeName, lst)); } codeNamespace.Types.Add(xroot); } }