From 59172035bcc17c9b66d9bc43269bfb7f82d3faa6 Mon Sep 17 00:00:00 2001 From: grudolf Date: Wed, 12 Dec 2018 23:17:47 +0100 Subject: [PATCH] Added control over XmlSchemaSet checking for Unique Particle Attribution (UPA) violations. --- XmlSchemaClassGenerator.Console/Program.cs | 5 ++++- XmlSchemaClassGenerator/Generator.cs | 7 +++++++ XmlSchemaClassGenerator/GeneratorConfiguration.cs | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/XmlSchemaClassGenerator.Console/Program.cs b/XmlSchemaClassGenerator.Console/Program.cs index 7633734f..7296b2c7 100644 --- a/XmlSchemaClassGenerator.Console/Program.cs +++ b/XmlSchemaClassGenerator.Console/Program.cs @@ -38,6 +38,7 @@ static void Main(string[] args) var disableComments = false; var doNotUseUnderscoreInPrivateMemberNames = false; var generateDescriptionAttribute = true; + var enableUpaCheck = true; var options = new OptionSet { { "h|help", "show this message and exit", v => showHelp = v != null }, @@ -74,6 +75,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l { "f|ef", "generate Entity Framework Code First compatible classes", v => entityFramework = v != null }, { "t|interface", "generate interfaces for groups and attribute groups (default is enabled)", v => interfaces = v != null }, { "a|pascal", "use Pascal case for class and property names (default is enabled)", v => pascal = v != null }, + { "u|enableUpaCheck", "should XmlSchemaSet check for Unique Particle Attribution (UPA) (default is enabled)", v => enableUpaCheck = v != null }, { "ct|collectionType=", "collection type to use (default is " + typeof(Collection<>).FullName + ")", v => collectionType = v == null ? typeof(Collection<>) : Type.GetType(v, true) }, { "cit|collectionImplementationType=", "the default collection type implementation to use (default is null)", v => collectionImplementationType = v == null ? null : Type.GetType(v, true) }, { "ctro|codeTypeReferenceOptions=", "the default CodeTypeReferenceOptions Flags to use (default is unset; can be: {GlobalReference, GenericTypeParameter})", v => codeTypeReferenceOptions = v == null ? default(CodeTypeReferenceOptions) : (CodeTypeReferenceOptions)Enum.Parse(typeof(CodeTypeReferenceOptions), v, false) }, @@ -126,7 +128,8 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l GenerateDebuggerStepThroughAttribute = generateDebuggerStepThroughAttribute, DisableComments = disableComments, GenerateDescriptionAttribute = generateDescriptionAttribute, - DoNotUseUnderscoreInPrivateMemberNames = doNotUseUnderscoreInPrivateMemberNames + DoNotUseUnderscoreInPrivateMemberNames = doNotUseUnderscoreInPrivateMemberNames, + EnableUpaCheck = enableUpaCheck }; if (pclCompatible) diff --git a/XmlSchemaClassGenerator/Generator.cs b/XmlSchemaClassGenerator/Generator.cs index 97149406..b0f34d8c 100644 --- a/XmlSchemaClassGenerator/Generator.cs +++ b/XmlSchemaClassGenerator/Generator.cs @@ -193,6 +193,12 @@ public bool DoNotUseUnderscoreInPrivateMemberNames set { _configuration.DoNotUseUnderscoreInPrivateMemberNames = value; } } + public bool EnableUpaCheck + { + get { return _configuration.EnableUpaCheck; } + set { _configuration.EnableUpaCheck = value; } + } + public void Generate(IEnumerable files) { var set = new XmlSchemaSet(); @@ -216,6 +222,7 @@ public void Generate(IEnumerable files) public void Generate(XmlSchemaSet set) { + set.CompilationSettings.EnableUpaCheck = EnableUpaCheck; set.Compile(); var m = new ModelBuilder(_configuration, set); diff --git a/XmlSchemaClassGenerator/GeneratorConfiguration.cs b/XmlSchemaClassGenerator/GeneratorConfiguration.cs index 8df128b7..343f7db4 100644 --- a/XmlSchemaClassGenerator/GeneratorConfiguration.cs +++ b/XmlSchemaClassGenerator/GeneratorConfiguration.cs @@ -35,6 +35,7 @@ public GeneratorConfiguration() MemberVisitor = (member, model) => { }; NamingProvider = new NamingProvider(NamingScheme); Version = VersionProvider.CreateFromAssembly(); + EnableUpaCheck = true; } /// @@ -171,5 +172,10 @@ public void WriteLog(string message) public bool DisableComments { get; set; } public bool DoNotUseUnderscoreInPrivateMemberNames { get; set; } + + /// + /// Check for Unique Particle Attribution (UPA) violations + /// + public bool EnableUpaCheck { get; set; } } }