diff --git a/XmlSchemaClassGenerator.Console/Program.cs b/XmlSchemaClassGenerator.Console/Program.cs index f2bfabe2..86a5ea09 100644 --- a/XmlSchemaClassGenerator.Console/Program.cs +++ b/XmlSchemaClassGenerator.Console/Program.cs @@ -53,6 +53,7 @@ static void Main(string[] args) var supportedCommentLanguages = new[] { "en", "de" }; var uniqueTypeNamesAcrossNamespaces = false; var createGeneratedCodeAttributeVersion = true; + var netCoreSpecificCode = false; var options = new OptionSet { { "h|help", "show this message and exit", v => showHelp = v != null }, @@ -124,6 +125,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l v => commentLanguages = v.Split(',').Select(l => l.Trim()).ToArray() }, { "un|uniqueTypeNames", "generate type names that are unique across namespaces (default is false)", v => uniqueTypeNamesAcrossNamespaces = v != null }, { "gc|generatedCodeAttribute", "add version information to GeneratedCodeAttribute (default is true)", v => createGeneratedCodeAttributeVersion = v != null }, + { "nc|netCore", "generate .NET Core specific code that might not work with .NET Framework (default is false)", v => netCoreSpecificCode = v != null }, }; var globsAndUris = options.Parse(args); @@ -197,7 +199,8 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l SeparateSubstitutes = separateSubstitutes, CompactTypeNames = compactTypeNames, UniqueTypeNamesAcrossNamespaces = uniqueTypeNamesAcrossNamespaces, - CreateGeneratedCodeAttributeVersion = createGeneratedCodeAttributeVersion + CreateGeneratedCodeAttributeVersion = createGeneratedCodeAttributeVersion, + NetCoreSpecificCode = netCoreSpecificCode }; generator.CommentLanguages.AddRange(commentLanguages); diff --git a/XmlSchemaClassGenerator.Tests/Compiler.cs b/XmlSchemaClassGenerator.Tests/Compiler.cs index a23fa052..0782576c 100644 --- a/XmlSchemaClassGenerator.Tests/Compiler.cs +++ b/XmlSchemaClassGenerator.Tests/Compiler.cs @@ -111,7 +111,8 @@ public static Assembly GenerateFiles(string name, IEnumerable files, Gen SeparateSubstitutes = generatorPrototype.SeparateSubstitutes, CompactTypeNames = generatorPrototype.CompactTypeNames, UniqueTypeNamesAcrossNamespaces = generatorPrototype.UniqueTypeNamesAcrossNamespaces, - CreateGeneratedCodeAttributeVersion = generatorPrototype.CreateGeneratedCodeAttributeVersion + CreateGeneratedCodeAttributeVersion = generatorPrototype.CreateGeneratedCodeAttributeVersion, + NetCoreSpecificCode = generatorPrototype.NetCoreSpecificCode }; gen.CommentLanguages.Clear(); diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index 107e4028..6b3e1ae1 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -55,7 +55,8 @@ private static IEnumerable ConvertXml(string name, IEnumerable x MemberVisitor = generatorPrototype.MemberVisitor, CodeTypeReferenceOptions = generatorPrototype.CodeTypeReferenceOptions, DoNotForceIsNullable = generatorPrototype.DoNotForceIsNullable, - CreateGeneratedCodeAttributeVersion = generatorPrototype.CreateGeneratedCodeAttributeVersion + CreateGeneratedCodeAttributeVersion = generatorPrototype.CreateGeneratedCodeAttributeVersion, + NetCoreSpecificCode = generatorPrototype.NetCoreSpecificCode }; gen.CommentLanguages.Clear(); @@ -310,7 +311,8 @@ public void TestSimple() GenerateInterfaces = true, NamespacePrefix = "Simple", GenerateDescriptionAttribute = true, - CodeTypeReferenceOptions = CodeTypeReferenceOptions.GlobalReference + CodeTypeReferenceOptions = CodeTypeReferenceOptions.GlobalReference, + NetCoreSpecificCode = true }); TestSamples("Simple", SimplePattern); } diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index 4af5c042..3589f0e5 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -178,6 +178,7 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig { XmlTypeCode.AnyAtomicType => typeof(string),// union XmlTypeCode.AnyUri or XmlTypeCode.GDay or XmlTypeCode.GMonth or XmlTypeCode.GMonthDay or XmlTypeCode.GYear or XmlTypeCode.GYearMonth => typeof(string), + XmlTypeCode.Duration => configuration.NetCoreSpecificCode ? type.ValueType : typeof(string), XmlTypeCode.Time => typeof(DateTime), XmlTypeCode.Idref => typeof(string), XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonNegativeInteger or XmlTypeCode.NonPositiveInteger or XmlTypeCode.PositiveInteger => GetIntegerDerivedType(type, configuration, restrictions), diff --git a/XmlSchemaClassGenerator/Generator.cs b/XmlSchemaClassGenerator/Generator.cs index e699f368..8bb4690e 100644 --- a/XmlSchemaClassGenerator/Generator.cs +++ b/XmlSchemaClassGenerator/Generator.cs @@ -282,6 +282,12 @@ public bool CreateGeneratedCodeAttributeVersion set { _configuration.CreateGeneratedCodeAttributeVersion = value; } } + public bool NetCoreSpecificCode + { + get { return _configuration.NetCoreSpecificCode; } + set { _configuration.NetCoreSpecificCode = value; } + } + static Generator() { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); diff --git a/XmlSchemaClassGenerator/GeneratorConfiguration.cs b/XmlSchemaClassGenerator/GeneratorConfiguration.cs index 63230155..80e79d7b 100644 --- a/XmlSchemaClassGenerator/GeneratorConfiguration.cs +++ b/XmlSchemaClassGenerator/GeneratorConfiguration.cs @@ -295,5 +295,14 @@ public void WriteLog(string message) /// Adds version information to . Default is true. /// public bool CreateGeneratedCodeAttributeVersion { get; set; } = true; + + /// + /// Generate code that works with .NET Core but might be incompatible with .NET Framework. Default is false. + /// Specific differences: + /// + /// Use for duration instead of string + /// + /// + public bool NetCoreSpecificCode { get; set; } } }