Skip to content

Commit 3a0a1bb

Browse files
author
Michael Ganss
committed
Use Configuration.CodeTypeReferenceOptions everywhere CodeTypeReferences are created
1 parent 282893b commit 3a0a1bb

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

XmlSchemaClassGenerator.Console/XmlSchemaClassGenerator.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</None>
2828
</ItemGroup>
2929
<ItemGroup>
30-
<PackageReference Include="Glob.cs" Version="2.0.13" />
30+
<PackageReference Include="Glob.cs" Version="3.0.27" />
3131
<PackageReference Include="Mono.Options" Version="5.3.0.1" />
3232
</ItemGroup>
3333
</Project>

XmlSchemaClassGenerator.Tests/Compiler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static Assembly GenerateFiles(string name, IEnumerable<string> files, Gen
8282
EntityFramework = false,
8383
GenerateInterfaces = true,
8484
NamespacePrefix = name,
85-
GenerateDescriptionAttribute = true
85+
GenerateDescriptionAttribute = true,
8686
};
8787

8888
var output = new FileWatcherOutputWriter(Path.Combine("output", name));
@@ -99,7 +99,8 @@ public static Assembly GenerateFiles(string name, IEnumerable<string> files, Gen
9999
EntityFramework = generatorPrototype.EntityFramework,
100100
GenerateInterfaces = generatorPrototype.GenerateInterfaces,
101101
MemberVisitor = generatorPrototype.MemberVisitor,
102-
GenerateDescriptionAttribute = generatorPrototype.GenerateDescriptionAttribute
102+
GenerateDescriptionAttribute = generatorPrototype.GenerateDescriptionAttribute,
103+
CodeTypeReferenceOptions = generatorPrototype.CodeTypeReferenceOptions
103104
};
104105

105106
gen.Generate(files);

XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
<ProjectReference Include="..\XmlSchemaClassGenerator\XmlSchemaClassGenerator.csproj" />
1919
</ItemGroup>
2020
<ItemGroup>
21-
<PackageReference Include="coverlet.msbuild" Version="2.4.0">
21+
<PackageReference Include="coverlet.msbuild" Version="2.6.2">
2222
<PrivateAssets>all</PrivateAssets>
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2424
</PackageReference>
25-
<PackageReference Include="Glob.cs" Version="2.0.13" />
25+
<PackageReference Include="Glob.cs" Version="3.0.27" />
2626
<PackageReference Include="Microsoft.Net.Compilers.netcore" Version="1.3.2" />
27-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
27+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
2828
<PackageReference Include="System.CodeDom" Version="4.5.0" />
29-
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0" />
29+
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
3030
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
3131
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
3232
<PrivateAssets>all</PrivateAssets>

XmlSchemaClassGenerator.Tests/XmlTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,19 @@ public void TestList()
114114
[UseCulture("en-US")]
115115
public void TestSimple()
116116
{
117-
Compiler.Generate("Simple", SimplePattern);
117+
Compiler.Generate("Simple", SimplePattern, new Generator
118+
{
119+
GenerateNullables = true,
120+
IntegerDataType = typeof(int),
121+
DataAnnotationMode = DataAnnotationMode.All,
122+
GenerateDesignerCategoryAttribute = false,
123+
GenerateComplexTypesForCollections = true,
124+
EntityFramework = false,
125+
GenerateInterfaces = true,
126+
NamespacePrefix = "Simple",
127+
GenerateDescriptionAttribute = true,
128+
CodeTypeReferenceOptions = CodeTypeReferenceOptions.GlobalReference
129+
});
118130
TestSamples("Simple", SimplePattern);
119131
}
120132

XmlSchemaClassGenerator.Tests/xsd/simple/simple.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
<xs:list itemType="xs:unsignedShort" />
386386
</xs:simpleType>
387387
</xs:attribute>
388+
<xs:attribute name="System" type="xs:string"></xs:attribute>
388389
</xs:complexType>
389390
</xs:element>
390391
</xs:schema>

XmlSchemaClassGenerator/RestrictionModel.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public override DataAnnotationMode MinimumDataAnnotationMode
8989

9090
public override CodeAttributeDeclaration GetAttribute()
9191
{
92-
var a = new CodeAttributeDeclaration(new CodeTypeReference(typeof(StringLengthAttribute)),
92+
var a = new CodeAttributeDeclaration(new CodeTypeReference(typeof(StringLengthAttribute), Configuration.CodeTypeReferenceOptions),
9393
new CodeAttributeArgument(Max > 0 ? (CodeExpression)new CodePrimitiveExpression(Max) : new CodeSnippetExpression("int.MaxValue")));
9494
if (Min > 0) { a.Arguments.Add(new CodeAttributeArgument("MinimumLength", new CodePrimitiveExpression(Min))); }
9595

@@ -120,7 +120,8 @@ public override DataAnnotationMode MinimumDataAnnotationMode
120120

121121
public override CodeAttributeDeclaration GetAttribute()
122122
{
123-
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MaxLengthAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
123+
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MaxLengthAttribute), Configuration.CodeTypeReferenceOptions),
124+
new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
124125
}
125126
}
126127

@@ -147,7 +148,8 @@ public override DataAnnotationMode MinimumDataAnnotationMode
147148

148149
public override CodeAttributeDeclaration GetAttribute()
149150
{
150-
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MinLengthAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
151+
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MinLengthAttribute), Configuration.CodeTypeReferenceOptions),
152+
new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
151153
}
152154
}
153155

@@ -218,7 +220,8 @@ public override DataAnnotationMode MinimumDataAnnotationMode
218220

219221
public override CodeAttributeDeclaration GetAttribute()
220222
{
221-
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(RegularExpressionAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
223+
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(RegularExpressionAttribute), Configuration.CodeTypeReferenceOptions),
224+
new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
222225
}
223226
}
224227

XmlSchemaClassGenerator/TypeModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public virtual CodeTypeReference GetReferenceFor(NamespaceModel referencingNames
184184
name = forInit ? SimpleModel.GetCollectionImplementationName(name, Configuration) : SimpleModel.GetCollectionDefinitionName(name, Configuration);
185185
}
186186

187-
return new CodeTypeReference(name);
187+
return new CodeTypeReference(name, Configuration.CodeTypeReferenceOptions);
188188
}
189189

190190
public virtual CodeExpression GetDefaultValueFor(string defaultString, bool attribute)
@@ -910,7 +910,7 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi
910910
{
911911
var specifiedProperty = new CodeMemberProperty
912912
{
913-
Type = new CodeTypeReference(typeof(bool)),
913+
Type = new CodeTypeReference(typeof(bool), Configuration.CodeTypeReferenceOptions),
914914
Name = Name + "Specified",
915915
HasSet = false,
916916
HasGet = true,
@@ -1268,7 +1268,8 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
12681268
}
12691269
else if (type == typeof(DateTime))
12701270
{
1271-
var rv = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(DateTime)), "Parse", new CodePrimitiveExpression(defaultString));
1271+
var rv = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(new CodeTypeReference(typeof(DateTime), Configuration.CodeTypeReferenceOptions)),
1272+
"Parse", new CodePrimitiveExpression(defaultString));
12721273
return rv;
12731274
}
12741275
else if (type == typeof(bool) && !string.IsNullOrWhiteSpace(defaultString))

0 commit comments

Comments
 (0)