Skip to content

Commit

Permalink
Use Configuration.CodeTypeReferenceOptions everywhere CodeTypeReferen…
Browse files Browse the repository at this point in the history
…ces are created
  • Loading branch information
Michael Ganss committed Jun 25, 2019
1 parent 282893b commit 3a0a1bb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Glob.cs" Version="2.0.13" />
<PackageReference Include="Glob.cs" Version="3.0.27" />
<PackageReference Include="Mono.Options" Version="5.3.0.1" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions XmlSchemaClassGenerator.Tests/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static Assembly GenerateFiles(string name, IEnumerable<string> files, Gen
EntityFramework = false,
GenerateInterfaces = true,
NamespacePrefix = name,
GenerateDescriptionAttribute = true
GenerateDescriptionAttribute = true,
};

var output = new FileWatcherOutputWriter(Path.Combine("output", name));
Expand All @@ -99,7 +99,8 @@ public static Assembly GenerateFiles(string name, IEnumerable<string> files, Gen
EntityFramework = generatorPrototype.EntityFramework,
GenerateInterfaces = generatorPrototype.GenerateInterfaces,
MemberVisitor = generatorPrototype.MemberVisitor,
GenerateDescriptionAttribute = generatorPrototype.GenerateDescriptionAttribute
GenerateDescriptionAttribute = generatorPrototype.GenerateDescriptionAttribute,
CodeTypeReferenceOptions = generatorPrototype.CodeTypeReferenceOptions
};

gen.Generate(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<ProjectReference Include="..\XmlSchemaClassGenerator\XmlSchemaClassGenerator.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.4.0">
<PackageReference Include="coverlet.msbuild" Version="2.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Glob.cs" Version="2.0.13" />
<PackageReference Include="Glob.cs" Version="3.0.27" />
<PackageReference Include="Microsoft.Net.Compilers.netcore" Version="1.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="System.CodeDom" Version="4.5.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
14 changes: 13 additions & 1 deletion XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ public void TestList()
[UseCulture("en-US")]
public void TestSimple()
{
Compiler.Generate("Simple", SimplePattern);
Compiler.Generate("Simple", SimplePattern, new Generator
{
GenerateNullables = true,
IntegerDataType = typeof(int),
DataAnnotationMode = DataAnnotationMode.All,
GenerateDesignerCategoryAttribute = false,
GenerateComplexTypesForCollections = true,
EntityFramework = false,
GenerateInterfaces = true,
NamespacePrefix = "Simple",
GenerateDescriptionAttribute = true,
CodeTypeReferenceOptions = CodeTypeReferenceOptions.GlobalReference
});
TestSamples("Simple", SimplePattern);
}

Expand Down
1 change: 1 addition & 0 deletions XmlSchemaClassGenerator.Tests/xsd/simple/simple.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
<xs:list itemType="xs:unsignedShort" />
</xs:simpleType>
</xs:attribute>
<xs:attribute name="System" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
11 changes: 7 additions & 4 deletions XmlSchemaClassGenerator/RestrictionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override DataAnnotationMode MinimumDataAnnotationMode

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

Expand Down Expand Up @@ -120,7 +120,8 @@ public override DataAnnotationMode MinimumDataAnnotationMode

public override CodeAttributeDeclaration GetAttribute()
{
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MaxLengthAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MaxLengthAttribute), Configuration.CodeTypeReferenceOptions),
new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
}
}

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

public override CodeAttributeDeclaration GetAttribute()
{
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MinLengthAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(MinLengthAttribute), Configuration.CodeTypeReferenceOptions),
new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
}
}

Expand Down Expand Up @@ -218,7 +220,8 @@ public override DataAnnotationMode MinimumDataAnnotationMode

public override CodeAttributeDeclaration GetAttribute()
{
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(RegularExpressionAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
return new CodeAttributeDeclaration(new CodeTypeReference(typeof(RegularExpressionAttribute), Configuration.CodeTypeReferenceOptions),
new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
}
}

Expand Down
7 changes: 4 additions & 3 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public virtual CodeTypeReference GetReferenceFor(NamespaceModel referencingNames
name = forInit ? SimpleModel.GetCollectionImplementationName(name, Configuration) : SimpleModel.GetCollectionDefinitionName(name, Configuration);
}

return new CodeTypeReference(name);
return new CodeTypeReference(name, Configuration.CodeTypeReferenceOptions);
}

public virtual CodeExpression GetDefaultValueFor(string defaultString, bool attribute)
Expand Down Expand Up @@ -910,7 +910,7 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi
{
var specifiedProperty = new CodeMemberProperty
{
Type = new CodeTypeReference(typeof(bool)),
Type = new CodeTypeReference(typeof(bool), Configuration.CodeTypeReferenceOptions),
Name = Name + "Specified",
HasSet = false,
HasGet = true,
Expand Down Expand Up @@ -1268,7 +1268,8 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
}
else if (type == typeof(DateTime))
{
var rv = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(DateTime)), "Parse", new CodePrimitiveExpression(defaultString));
var rv = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(new CodeTypeReference(typeof(DateTime), Configuration.CodeTypeReferenceOptions)),
"Parse", new CodePrimitiveExpression(defaultString));
return rv;
}
else if (type == typeof(bool) && !string.IsNullOrWhiteSpace(defaultString))
Expand Down

0 comments on commit 3a0a1bb

Please sign in to comment.