Skip to content

Commit 5d31527

Browse files
author
Michael Ganss
committed
Use new()
1 parent c88b0d9 commit 5d31527

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

XmlSchemaClassGenerator.Tests/XmlTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private bool HandleValidationError(string[] xmlLines, ValidationEventArgs e)
522522
&& !e.Message.Contains("The Pattern constraint failed")); // generator doesn't generate valid values where pattern restrictions exist, e.g. email
523523
}
524524

525-
private static readonly XmlQualifiedName AnyType = new XmlQualifiedName("anyType", XmlSchema.Namespace);
525+
private static readonly XmlQualifiedName AnyType = new("anyType", XmlSchema.Namespace);
526526

527527
private void DeserializeSampleXml(string pattern, Assembly assembly)
528528
{
@@ -691,7 +691,7 @@ public void TestCustomNamespaces()
691691
string dcXsd = "DC.xsd";
692692
string diXsd = "DI.xsd";
693693

694-
Dictionary<string, string> xsdToCsharpNsMap = new Dictionary<string, string>
694+
Dictionary<string, string> xsdToCsharpNsMap = new()
695695
{
696696
{ bpmnXsd, "Namespace1" },
697697
{ semantXsd, "Namespace1" },
@@ -700,7 +700,7 @@ public void TestCustomNamespaces()
700700
{ diXsd, "Namespace4" }
701701
};
702702

703-
Dictionary<string, string> xsdToCsharpTypeMap = new Dictionary<string, string>
703+
Dictionary<string, string> xsdToCsharpTypeMap = new()
704704
{
705705
{ bpmnXsd, "TDefinitions" },
706706
{ semantXsd, "TActivity" },
@@ -709,7 +709,7 @@ public void TestCustomNamespaces()
709709
{ diXsd, "DiagramElement" }
710710
};
711711

712-
List<string> customNamespaceConfig = new List<string>();
712+
List<string> customNamespaceConfig = new();
713713

714714
foreach (var ns in xsdToCsharpNsMap)
715715
customNamespaceConfig.Add(string.Format(customNsPattern, ns.Key, ns.Value));
@@ -804,7 +804,7 @@ void UnknownAttributeHandler(object sender, XmlAttributeEventArgs e)
804804

805805
private static IDictionary<string, string> GetNamespacesFromSource(string source)
806806
{
807-
XPathDocument doc = new XPathDocument(new StringReader(source));
807+
XPathDocument doc = new(new StringReader(source));
808808
XPathNavigator namespaceNavigator = doc.CreateNavigator();
809809
namespaceNavigator.MoveToFollowing(XPathNodeType.Element);
810810
return namespaceNavigator.GetNamespacesInScope(XmlNamespaceScope.All);
@@ -2442,7 +2442,7 @@ namespace Test
24422442
[System.Xml.Serialization.XmlRootAttribute(""document"", Namespace=""http://local.none"")]
24432443
public partial class Elem
24442444
{{
2445-
2445+
24462446
[System.Xml.Serialization.XmlAttributeAttribute(""Text"")]
24472447
public string Text {{ get; set; }}
24482448
}}

XmlSchemaClassGenerator/ModelBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ internal class ModelBuilder
1414
private readonly XmlSchemaSet _set;
1515
private readonly Dictionary<XmlQualifiedName, XmlSchemaAttributeGroup> AttributeGroups;
1616
private readonly Dictionary<XmlQualifiedName, XmlSchemaGroup> Groups;
17-
private readonly Dictionary<NamespaceKey, NamespaceModel> Namespaces = new Dictionary<NamespaceKey, NamespaceModel>();
18-
private readonly Dictionary<string, TypeModel> Types = new Dictionary<string, TypeModel>();
19-
private readonly Dictionary<XmlQualifiedName, HashSet<Substitute>> SubstitutionGroups = new Dictionary<XmlQualifiedName, HashSet<Substitute>>();
17+
private readonly Dictionary<NamespaceKey, NamespaceModel> Namespaces = new();
18+
private readonly Dictionary<string, TypeModel> Types = new();
19+
private readonly Dictionary<XmlQualifiedName, HashSet<Substitute>> SubstitutionGroups = new();
2020

21-
private static readonly XmlQualifiedName AnyType = new XmlQualifiedName("anyType", XmlSchema.Namespace);
21+
private static readonly XmlQualifiedName AnyType = new("anyType", XmlSchema.Namespace);
2222

2323
private string BuildKey(XmlSchemaAnnotated annotated, XmlQualifiedName name)
2424
=> $"{annotated.GetType()}:{annotated.SourceUri}:{annotated.LineNumber}:{annotated.LinePosition}:{name}";
@@ -557,7 +557,7 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType,
557557
private TypeModel CreateTypeModel(XmlSchemaSimpleType simpleType, NamespaceModel namespaceModel, XmlQualifiedName qualifiedName, List<DocumentationModel> docs)
558558
{
559559
var restrictions = new List<RestrictionModel>();
560-
List<XmlSchemaFacet> facets = new List<XmlSchemaFacet>();
560+
List<XmlSchemaFacet> facets = new();
561561

562562
if (simpleType.Content is XmlSchemaSimpleTypeRestriction typeRestriction)
563563
facets = typeRestriction.Facets.Cast<XmlSchemaFacet>().ToList();

0 commit comments

Comments
 (0)