Skip to content

Commit

Permalink
Merge pull request #528 from mingyaulee/configuration-for-merge-restr…
Browse files Browse the repository at this point in the history
…ictions

Allow disabling of merging restrictions with base in configuration
  • Loading branch information
mganss authored Aug 30, 2024
2 parents 4120626 + fc1028a commit 9e2b96d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions XmlSchemaClassGenerator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static int Main(string[] args)
var generateCommandLineArgs = true;
var useArrayItemAttribute = true;
var enumAsString = false;
var disableMergeRestrictionsWithBase = false;
var namespaceFiles = new List<string>();
var nameSubstituteFiles = new List<string>();
var unionCommonType = false;
Expand Down Expand Up @@ -159,6 +160,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
{ "nr|nullableReferenceAttributes", "generate attributes for nullable reference types (default is false)", v => nullableReferenceAttributes = v != null },
{ "ar|useArrayItemAttribute", "use ArrayItemAttribute for sequences with single elements (default is true)", v => useArrayItemAttribute = v != null },
{ "es|enumAsString", "Use string instead of enum for enumeration", v => enumAsString = v != null },
{ "dmb|disableMergeRestrictionsWithBase", "Disable merging of simple type restrictions with base type restrictions", v => disableMergeRestrictionsWithBase = v != null },
{ "ca|commandArgs", "generate a comment with the exact command line arguments that were used to generate the source code (default is true)", v => generateCommandLineArgs = v != null },
{ "uc|unionCommonType", "generate a common type for unions if possible (default is false)", v => unionCommonType = v != null },
{ "ec|serializeEmptyCollections", "serialize empty collections (default is false)", v => serializeEmptyCollections = v != null },
Expand Down Expand Up @@ -259,6 +261,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
GenerateCommandLineArgumentsComment = generateCommandLineArgs,
UseArrayItemAttribute = useArrayItemAttribute,
EnumAsString = enumAsString,
MergeRestrictionsWithBase = !disableMergeRestrictionsWithBase,
MapUnionToWidestCommonType = unionCommonType,
SeparateNamespaceHierarchy = separateNamespaceHierarchy,
SerializeEmptyCollections = serializeEmptyCollections,
Expand Down
6 changes: 6 additions & 0 deletions XmlSchemaClassGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public bool EnumAsString
set { _configuration.EnumAsString = value; }
}

public bool MergeRestrictionsWithBase
{
get { return _configuration.MergeRestrictionsWithBase; }
set { _configuration.MergeRestrictionsWithBase = value; }
}

public bool GenerateComplexTypesForCollections
{
get { return _configuration.GenerateComplexTypesForCollections; }
Expand Down
3 changes: 3 additions & 0 deletions XmlSchemaClassGenerator/GeneratorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ public GeneratorConfiguration()
Version = VersionProvider.CreateFromAssembly();
EnableUpaCheck = true;
CommandLineArgumentsProvider = CommandLineArgumentsProvider.CreateFromEnvironment();
MergeRestrictionsWithBase = true;
}

public bool EnumAsString { get; set; }

public bool MergeRestrictionsWithBase { get; set; }

/// <summary>
/// The writer to be used to generate the code files
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion XmlSchemaClassGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType)

var facets = simpleType.Content switch
{
XmlSchemaSimpleTypeRestriction typeRestriction when !_configuration.MergeRestrictionsWithBase => typeRestriction.Facets.Cast<XmlSchemaFacet>().ToList(),
XmlSchemaSimpleTypeUnion typeUnion when AllMembersHaveFacets(typeUnion, out baseFacets) => baseFacets.SelectMany(f => f).ToList(),
_ => MergeRestrictions(simpleType)
};
Expand Down Expand Up @@ -1108,4 +1109,4 @@ private string BuildNamespace(Uri source, string xmlNamespace)
: throw new ArgumentException(string.Format("Namespace {0} not provided through map or generator.", xmlNamespace));
}
}
}
}

0 comments on commit 9e2b96d

Please sign in to comment.