當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlSchemaSet.AddMaindocSchemas方法代碼示例

本文整理匯總了C#中System.Xml.Schema.XmlSchemaSet.AddMaindocSchemas方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlSchemaSet.AddMaindocSchemas方法的具體用法?C# XmlSchemaSet.AddMaindocSchemas怎麽用?C# XmlSchemaSet.AddMaindocSchemas使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Schema.XmlSchemaSet的用法示例。


在下文中一共展示了XmlSchemaSet.AddMaindocSchemas方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        static void Main(string[] args)
        {
            UblXsdSettings ublSettings = new UblXsdSettings
            {
                XsdValidationEvent = SchemaValidationEventHandler,
                UblXsdInputPath = @"..\..\..\UBL-2.1\xsd",  // Content originally from ubl zip download.
                CodeGenOutputPath = @"..\..\..\UblLarsen.Ubl2",
                OptionOptimizeCommonBasicComponents = true, // remove yagni types from schema before code generation. tests wont work when this is set to false
                CSharpDefaultNamespace = "UblLarsen.Ubl2",
                OptionMemberTypeToGenerate = UblXsdSettings.FieldTypesEnum.AutoProperty // or Field, or Property
            };

            XmlSchemaSet schemaSet = new XmlSchemaSet(new NameTable());
            schemaSet.ValidationEventHandler += SchemaValidationEventHandler;
            // Read and add the xsd documents in xsd/maindoc folder
            schemaSet.AddMaindocSchemas(ublSettings);
            schemaSet.Compile();

            if (ublSettings.OptionOptimizeCommonBasicComponents)
            {
                var cbcSchema = schemaSet.Schemas(Constants.CommonBasicComponentsTargetNamespace).Cast<XmlSchema>().Single();
                UblSchemaTypeSimplificationTool.SimplifyCommonBasicComponentsTypes(cbcSchema);
                schemaSet.Reprocess(cbcSchema);
                schemaSet.Compile();
            }

            UblSchemaTypeSimplificationTool.ResolveTypeNameClashesByRenaming(schemaSet);
            schemaSet.Compile();

            var abstractMaindocBaseSchema = UblSchemaInheritanceTools.ModifyMaindocSchemasForInheritance(schemaSet.MaindocSchemas());
            abstractMaindocBaseSchema = schemaSet.Add(abstractMaindocBaseSchema);
            schemaSet.MaindocSchemas().Where(s => s != abstractMaindocBaseSchema).ToList().ForEach(s => schemaSet.Reprocess(s));
            schemaSet.Compile();

            UblCodeGenerator gen = new UblCodeGenerator(ublSettings);
            // namespacelist parameter will drag in all other dependent types. New extensions shold probably be appended here... or...
            var allCodeDecls = gen.CreateCodeTypeDeclarations(schemaSet, 
                new[] {
                    Constants.BaseDocumentTargetNamespace,
                    Constants.SignatureAggregateComponents,
                    Constants.CommonSignatureComponentsTargetNamespace,
                    Constants.Xadesv141TargetNamespace}
                );

            UblDocumentationTool.AddDocumentation(allCodeDecls);

            UblImplicitAssignmentTool.AddImplicitAssignmentOperatorsForXmlTextAttributedDecendants(allCodeDecls);

            XsdTimeTool.IgnoreDateTimeSerializeAsString(allCodeDecls.Where(c => c.Name == "TimeType").Single());

            var mainDocCodeDecls = allCodeDecls.Where(c => c.BaseTypes.Count == 1 && c.BaseTypes[0].BaseType == Constants.abstractBaseSchemaComplexTypeName);
            MainDocsAttributeTool.RenameTopLevelXmlType(mainDocCodeDecls);
            MainDocsAttributeTool.AddXmlRootAttributes(mainDocCodeDecls);

            gen.GenerateAndSaveCodeFilesBySchema(allCodeDecls, new UblNamespaceManager(schemaSet, ublSettings.CSharpDefaultNamespace, ublSettings.OptionOptimizeCommonBasicComponents));

            UblSchemaStatsTool.ShowStats(allCodeDecls);

            Console.WriteLine("DONE");
            Console.ReadLine();
        }
開發者ID:Gammern,項目名稱:ubllarsen,代碼行數:61,代碼來源:Program.cs


注:本文中的System.Xml.Schema.XmlSchemaSet.AddMaindocSchemas方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。