Skip to content

Commit 4ee90be

Browse files
authored
Merge pull request #85 from jokokko/master
EditorBrowsableAttribute values should respect CodeTypeReferenceOptio…
2 parents c24c965 + b3c1867 commit 4ee90be

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

XmlSchemaClassGenerator.Tests/XmlTests.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.CodeAnalysis;
33
using Microsoft.Xml.XMLGen;
44
using System;
5+
using System.CodeDom;
56
using System.Collections.Generic;
67
using System.IO;
78
using System.Linq;
@@ -34,6 +35,7 @@ private IEnumerable<string> ConvertXml(string name, string xsd, Generator genera
3435
EntityFramework = generatorPrototype.EntityFramework,
3536
GenerateInterfaces = generatorPrototype.GenerateInterfaces,
3637
MemberVisitor = generatorPrototype.MemberVisitor,
38+
CodeTypeReferenceOptions = generatorPrototype.CodeTypeReferenceOptions
3739
};
3840

3941
var set = new XmlSchemaSet();
@@ -338,7 +340,45 @@ public void DontGenerateElementForEmptyCollectionInChoice()
338340
Assert.DoesNotContain("tags", xml, StringComparison.OrdinalIgnoreCase);
339341
}
340342

341-
[Fact]
343+
344+
[Theory]
345+
[InlineData(CodeTypeReferenceOptions.GlobalReference, "[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]")]
346+
[InlineData((CodeTypeReferenceOptions)0, "[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]")]
347+
public void EditorBrowsableAttributeRespectsCodeTypeReferenceOptions(CodeTypeReferenceOptions codeTypeReferenceOptions, string expectedLine)
348+
{
349+
const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
350+
<xs:schema elementFormDefault=""qualified"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
351+
<xs:complexType name=""document"">
352+
<xs:attribute name=""some-value"">
353+
<xs:simpleType>
354+
<xs:restriction base=""xs:string"">
355+
<xs:enumeration value=""one""/>
356+
<xs:enumeration value=""two""/>
357+
</xs:restriction>
358+
</xs:simpleType>
359+
</xs:attribute>
360+
<xs:attribute name=""system"" type=""xs:string""/>
361+
</xs:complexType>
362+
</xs:schema>";
363+
364+
var generatedType = ConvertXml(nameof(EditorBrowsableAttributeRespectsCodeTypeReferenceOptions), xsd, new Generator
365+
{
366+
CodeTypeReferenceOptions = codeTypeReferenceOptions,
367+
GenerateNullables = true,
368+
GenerateInterfaces = false,
369+
NamespaceProvider = new NamespaceProvider
370+
{
371+
GenerateNamespace = key => "Test"
372+
}
373+
});
374+
375+
Assert.Contains(
376+
expectedLine,
377+
generatedType.First());
378+
}
379+
380+
381+
[Fact]
342382
public void ComplexTypeWithAttributeGroupExtension()
343383
{
344384
const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>

XmlSchemaClassGenerator/TypeModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,8 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi
850850
typeDeclaration.Members.Add(nullableMember);
851851

852852
var editorBrowsableAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(EditorBrowsableAttribute), Configuration.CodeTypeReferenceOptions));
853-
editorBrowsableAttribute.Arguments.Add(new CodeAttributeArgument(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(EditorBrowsableState)), "Never")));
854-
specifiedMember.CustomAttributes.Add(editorBrowsableAttribute);
853+
editorBrowsableAttribute.Arguments.Add(new CodeAttributeArgument(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(new CodeTypeReference(typeof(EditorBrowsableState), Configuration.CodeTypeReferenceOptions)), "Never")));
854+
specifiedMember.CustomAttributes.Add(editorBrowsableAttribute);
855855
member.CustomAttributes.Add(editorBrowsableAttribute);
856856
if (Configuration.EntityFramework) { member.CustomAttributes.Add(notMappedAttribute); }
857857
}

0 commit comments

Comments
 (0)