From 738e3333c5459402341ed9a6badfa12097508b5b Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Thu, 22 Feb 2018 17:01:16 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20#49=20Update=20NuGet=20packages=20?= =?UTF-8?q?=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XmlSchemaClassGenerator.Console/Glob.cs | 2 +- XmlSchemaClassGenerator.Console/Program.cs | 4 ++-- .../NamespaceProviderTests.cs | 8 ++++---- .../XmlSchemaClassGenerator.Tests.csproj | 12 ++++++------ .../XsdElsterDatenabholung5.cs | 2 +- XmlSchemaClassGenerator/GeneratorConfiguration.cs | 4 +++- XmlSchemaClassGenerator/TypeModel.cs | 3 +-- .../XmlSchemaClassGenerator.csproj | 4 ++++ 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/XmlSchemaClassGenerator.Console/Glob.cs b/XmlSchemaClassGenerator.Console/Glob.cs index 0c3d03fb..364fc77a 100644 --- a/XmlSchemaClassGenerator.Console/Glob.cs +++ b/XmlSchemaClassGenerator.Console/Glob.cs @@ -494,7 +494,7 @@ public override string ToString() /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { diff --git a/XmlSchemaClassGenerator.Console/Program.cs b/XmlSchemaClassGenerator.Console/Program.cs index 61d4d233..0e95e8ee 100644 --- a/XmlSchemaClassGenerator.Console/Program.cs +++ b/XmlSchemaClassGenerator.Console/Program.cs @@ -92,7 +92,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l var namespaceMap = namespaces.Select(n => ParseNamespace(n, namespacePrefix)).ToNamespaceProvider(key => { var xn = key.XmlSchemaNamespace; - var name = string.Join(".", xn.Split('/').Where(p => Regex.IsMatch(p, @"^[A-Za-z]+$") && p != "schema") + var name = string.Join(".", xn.Split('/').Where(p => p != "schema" && GeneratorConfiguration.IdentifierRegex.IsMatch(p)) .Select(n => n.ToTitleCase(NamingScheme.PascalCase))); if (!string.IsNullOrEmpty(namespacePrefix)) { name = namespacePrefix + (string.IsNullOrEmpty(name) ? "" : ("." + name)); } return name; @@ -132,7 +132,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l } if (verbose) { generator.Log = s => System.Console.Out.WriteLine(s); } - + generator.Generate(files); } diff --git a/XmlSchemaClassGenerator.Tests/NamespaceProviderTests.cs b/XmlSchemaClassGenerator.Tests/NamespaceProviderTests.cs index 90b95f0b..123ccec8 100644 --- a/XmlSchemaClassGenerator.Tests/NamespaceProviderTests.cs +++ b/XmlSchemaClassGenerator.Tests/NamespaceProviderTests.cs @@ -20,7 +20,7 @@ public void ContainsKeyTest() Assert.True(ns.ContainsKey(new NamespaceKey("y"))); Assert.False(ns.ContainsKey(new NamespaceKey("z"))); ns.Clear(); - Assert.Equal(0, ns.Count); + Assert.Empty(ns); } [Fact] @@ -37,9 +37,9 @@ public void IndexTest() var ns = new NamespaceProvider(); ns[new NamespaceKey("x")] = "c"; ns.GenerateNamespace = k => k.XmlSchemaNamespace != "z" ? k.XmlSchemaNamespace : null; - Assert.Equal(ns[new NamespaceKey("x")], "c"); - Assert.Equal(ns[new NamespaceKey("y")], "y"); - Assert.Equal(ns[new NamespaceKey("y")], "y"); + Assert.Equal("c", ns[new NamespaceKey("x")]); + Assert.Equal("y", ns[new NamespaceKey("y")]); + Assert.Equal("y", ns[new NamespaceKey("y")]); Assert.Throws(() => ns[new NamespaceKey("z")]); } } diff --git a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj index 0fb52fb7..32f58cec 100644 --- a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj +++ b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj @@ -21,12 +21,12 @@ - - - - - - + + + + + + diff --git a/XmlSchemaClassGenerator.Tests/XsdElsterDatenabholung5.cs b/XmlSchemaClassGenerator.Tests/XsdElsterDatenabholung5.cs index c0d83476..7a339743 100644 --- a/XmlSchemaClassGenerator.Tests/XsdElsterDatenabholung5.cs +++ b/XmlSchemaClassGenerator.Tests/XsdElsterDatenabholung5.cs @@ -88,7 +88,7 @@ public void CanCompileClasses() var outputName = Path.Combine(outputPath, "Elster.Test.dll"); var fileNames = new DirectoryInfo(inputPath).GetFiles("*.cs").Select(x => x.FullName).ToArray(); var results = provider.CompileAssemblyFromFile(new CompilerParameters(assemblies, outputName), fileNames); - Assert.Equal(0, results.Errors.Count); + Assert.Empty(results.Errors); results.CompiledAssembly.GetType("Elster.Datenabholung5.Elster", true); results.CompiledAssembly.GetType("Elster.Basis.TransferHeaderCType", true); } diff --git a/XmlSchemaClassGenerator/GeneratorConfiguration.cs b/XmlSchemaClassGenerator/GeneratorConfiguration.cs index 4c654c27..c16d02dc 100644 --- a/XmlSchemaClassGenerator/GeneratorConfiguration.cs +++ b/XmlSchemaClassGenerator/GeneratorConfiguration.cs @@ -11,6 +11,8 @@ namespace XmlSchemaClassGenerator { public class GeneratorConfiguration { + public static Regex IdentifierRegex = new Regex(@"^@?[_\p{L}\p{Nl}][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}]*$", RegexOptions.Compiled); + public GeneratorConfiguration() { NamespaceProvider = new NamespaceProvider() @@ -19,7 +21,7 @@ public GeneratorConfiguration() { var xn = key.XmlSchemaNamespace; var name = string.Join(".", - xn.Split('/').Where(p => Regex.IsMatch(p, @"^[A-Za-z]+$") && p != "schema") + xn.Split('/').Where(p => p != "schema" && IdentifierRegex.IsMatch(p)) .Select(n => n.ToTitleCase(NamingScheme.PascalCase))); if (!string.IsNullOrEmpty(NamespacePrefix)) { diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index fcd9ca4d..3d1b3325 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -597,10 +597,9 @@ private CodeTypeReference TypeReference private void AddDocs(CodeTypeMember member) { - var simpleType = PropertyType as SimpleModel; var docs = new List(Documentation); - if (simpleType != null) + if (PropertyType is SimpleModel simpleType) { docs.AddRange(simpleType.Documentation); docs.AddRange(simpleType.Restrictions.Select(r => new DocumentationModel { Language = "en", Text = r.Description })); diff --git a/XmlSchemaClassGenerator/XmlSchemaClassGenerator.csproj b/XmlSchemaClassGenerator/XmlSchemaClassGenerator.csproj index 5a75b9a4..318a9542 100644 --- a/XmlSchemaClassGenerator/XmlSchemaClassGenerator.csproj +++ b/XmlSchemaClassGenerator/XmlSchemaClassGenerator.csproj @@ -52,4 +52,8 @@ + + + +