Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow disabling of merging restrictions with base in configuration #528

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
set { _configuration.EnumAsString = value; }
}

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

Check warning on line 45 in XmlSchemaClassGenerator/Generator.cs

View check run for this annotation

Codecov / codecov/patch

XmlSchemaClassGenerator/Generator.cs#L44-L45

Added lines #L44 - L45 were not covered by tests
}

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));
}
}
}
}