public XsdToTypesConverter(LinqToXsdSettings configSettings) { this.configSettings = configSettings; symbolTable = new GlobalSymbolTable(configSettings); localSymbolTable = new LocalSymbolTable(configSettings); binding = new ClrMappingInfo(); textPropInheritanceTracker = new Dictionary<XmlSchemaType, ClrPropertyInfo>(); substitutionGroups = new Dictionary<XmlQualifiedName, ArrayList>(); }
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); } }
public static CodeSnippetTypeMember CreateXRootGetter(string typeName, string fqTypeName, LocalSymbolTable lst) { string symbolName = lst.AddMember(typeName); CodeSnippetTypeMember castMember = new CodeSnippetTypeMember(); castMember.Text = String.Concat("\r\n", " public ", fqTypeName, " ", symbolName, " { get {", "return rootObject as ", fqTypeName,"; } }"); return castMember; }
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); }
public static CodeSnippetTypeMember CreateXRootGetter(string typeName, string fqTypeName, LocalSymbolTable lst) { string symbolName = lst.AddMember(typeName); CodeSnippetTypeMember castMember = new CodeSnippetTypeMember(); castMember.Text = String.Concat("\r\n", " public ", fqTypeName, " ", symbolName, " { get {", "return rootObject as ", fqTypeName, "; } }"); return(castMember); }
public static CodeSnippetTypeMember CreateXRootGetter(string typeName, string fqTypeName, LocalSymbolTable lst, GeneratedTypesVisibility visibility = GeneratedTypesVisibility.Public) { string symbolName = lst.AddMember(typeName); CodeSnippetTypeMember castMember = new CodeSnippetTypeMember(); castMember.Text = String.Concat("\r\n", $"\t\t{visibility.ToKeyword()} ", fqTypeName, " ", symbolName, " { get {", "return rootObject as ", fqTypeName, "; } }"); return(castMember); }