Skip to content

Commit 0a7d156

Browse files
committed
Fix #556
Implement VS suggestions
1 parent 48e9dfc commit 0a7d156

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
1414
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
1515
<LangVersion>preview</LangVersion>
16-
<CoverletOutputFormat>opencover</CoverletOutputFormat>
17-
<CoverletOutput>../coverage.xml</CoverletOutput>
18-
<Include>[XmlSchemaClassGenerator]*</Include>
16+
<CoverletOutputFormat>opencover</CoverletOutputFormat>
17+
<CoverletOutput>../coverage.xml</CoverletOutput>
18+
<Include>[XmlSchemaClassGenerator]*</Include>
19+
<NoWarn>$(NoWarn);IDE0130;SYSLIB1045</NoWarn>
1920
</PropertyGroup>
2021
<ItemGroup>
2122
<ProjectReference Include="..\XmlSampleGenerator\XmlSampleGenerator.csproj" />

XmlSchemaClassGenerator.Tests/XmlTests.cs

+9-17
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public class XmlTests(ITestOutputHelper output)
2929

3030
private static IEnumerable<string> ConvertXml(string name, IEnumerable<string> xsds, Generator generatorPrototype = null)
3131
{
32-
if (name is null)
33-
{
34-
throw new ArgumentNullException(nameof(name));
35-
}
32+
ArgumentNullException.ThrowIfNull(name);
3633

3734
var writer = new MemoryOutputWriter();
3835

@@ -729,10 +726,7 @@ public void TestXbrl()
729726

730727
gen.NamespaceProvider.Add(new NamespaceKey("http://www.xbrl.org/2003/XLink"), "XbrlLink");
731728

732-
var xsdFiles = new[]
733-
{
734-
"xhtml-inlinexbrl-1_1.xsd",
735-
}.Select(x => Path.Combine(Directory.GetCurrentDirectory(), "xsd", "xbrl", x)).ToList();
729+
var xsdFiles = new[] { Path.Combine(Directory.GetCurrentDirectory(), "xsd", "xbrl", "xhtml-inlinexbrl-1_1.xsd") };
736730

737731
var assembly = Compiler.GenerateFiles("Xbrl", xsdFiles, gen);
738732
Assert.NotNull(assembly);
@@ -784,8 +778,8 @@ void UnknownAttributeHandler(object sender, XmlAttributeEventArgs e)
784778

785779
private static readonly XmlQualifiedName AnyType = new("anyType", XmlSchema.Namespace);
786780

787-
public static TheoryData<string> Classes => new()
788-
{
781+
public static TheoryData<string> Classes =>
782+
[
789783
"ApartmentBuy",
790784
"ApartmentRent",
791785
"AssistedLiving",
@@ -806,7 +800,7 @@ void UnknownAttributeHandler(object sender, XmlAttributeEventArgs e)
806800
"SpecialPurpose",
807801
"Store",
808802
"TradeSite",
809-
};
803+
];
810804

811805
[Theory, TestPriority(2)]
812806
[MemberData(nameof(Classes))]
@@ -1974,10 +1968,10 @@ public void RefTypesGetNoXmlElementAttributeTest()
19741968
var classType = assembly.GetType("Test.SampleRoot");
19751969
Assert.NotNull(classType);
19761970

1977-
var directProperty = Assert.Single(classType.GetProperties().Where(p => p.Name == "Direct"));
1971+
var directProperty = Assert.Single(classType.GetProperties(), p => p.Name == "Direct");
19781972
Assert.Equal(XmlSchemaForm.Unqualified, directProperty.GetCustomAttributes<XmlElementAttribute>().FirstOrDefault()?.Form);
19791973

1980-
var viaRefProperty = Assert.Single(classType.GetProperties().Where(p => p.Name == "ViaRef"));
1974+
var viaRefProperty = Assert.Single(classType.GetProperties(), p => p.Name == "ViaRef");
19811975
Assert.Equal(XmlSchemaForm.None, viaRefProperty.GetCustomAttributes<XmlElementAttribute>().FirstOrDefault()?.Form);
19821976
}
19831977

@@ -2718,10 +2712,8 @@ public void TestNetex()
27182712
GenerateInterfaces = false,
27192713
UniqueTypeNamesAcrossNamespaces = true,
27202714
};
2721-
var xsdFiles = new[]
2722-
{
2723-
"NeTEx_publication.xsd",
2724-
}.Select(x => Path.Combine(Directory.GetCurrentDirectory(), "xsd", "netex", x)).ToList();
2715+
2716+
var xsdFiles = new[] { Path.Combine(Directory.GetCurrentDirectory(), "xsd", "netex", "NeTEx_publication.xsd") };
27252717

27262718
var assembly = Compiler.GenerateFiles("Netex", xsdFiles, gen);
27272719
Assert.NotNull(assembly);

XmlSchemaClassGenerator/TypeModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
441441
{
442442
var rootClass = AllBaseTypes.LastOrDefault();
443443

444-
if (rootClass is SimpleModel)
444+
if (rootClass is SimpleModel || rootClass is EnumModel)
445445
{
446446
string reference, val;
447447

0 commit comments

Comments
 (0)