File tree Expand file tree Collapse file tree 5 files changed +57
-4
lines changed
XmlSchemaClassGenerator.Tests Expand file tree Collapse file tree 5 files changed +57
-4
lines changed Original file line number Diff line number Diff line change 128128 <None Update =" xml\office_min.xml" >
129129 <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
130130 </None >
131+ <None Update =" xml\sameattributenames.xsd" >
132+ <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
133+ </None >
134+ <None Update =" xml\sameattributenames_import.xsd" >
135+ <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
136+ </None >
131137 <None Update =" xml\seniorCare_max.xml" >
132138 <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
133139 </None >
Original file line number Diff line number Diff line change @@ -378,6 +378,16 @@ public void EditorBrowsableAttributeRespectsCodeTypeReferenceOptions(CodeTypeRef
378378 }
379379
380380
381+ [ Theory ]
382+ [ InlineData ( @"xml/sameattributenames.xsd" , @"xml/sameattributenames_import.xsd" ) ]
383+ public void CollidingAttributeAndPropertyNamesCanBeResolved ( params string [ ] files )
384+ {
385+ // Compilation would previously throw due to duplicate type name within type
386+ var assembly = Compiler . GenerateFiles ( "AttributesWithSameName" , files ) ;
387+
388+ Assert . NotNull ( assembly ) ;
389+ }
390+
381391 [ Fact ]
382392 public void ComplexTypeWithAttributeGroupExtension ( )
383393 {
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <schema xmlns =" http://www.w3.org/2001/XMLSchema" xmlns : a =" http://none.local/a" xmlns : b =" http://none.local/b" elementFormDefault =" qualified" targetNamespace =" http://none.local/a" >
3+ <import namespace =" http://none.local/b" schemaLocation =" sameattributenames_import.xsd" />
4+ <element name =" document" type =" a:elem" />
5+ <element name =" document2" type =" a:elem2" />
6+ <complexType name =" elem" >
7+ <sequence >
8+ <element name =" Type" type =" a:elem2" />
9+ </sequence >
10+ <attribute ref =" b:type" />
11+ <attribute name =" type" type =" string" />
12+ </complexType >
13+ <complexType name =" elem2" >
14+ <attribute name =" type" type =" string" />
15+ </complexType >
16+ </schema >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <xs : schema xmlns : xs =" http://www.w3.org/2001/XMLSchema" targetNamespace =" http://none.local/b" xmlns : b =" http://none.local/b" >
3+ <xs : attribute name =" type" type =" b:typeType" />
4+ <xs : simpleType name =" typeType" >
5+ <xs : restriction base =" xs:token" >
6+ <xs : enumeration value =" a" />
7+ <xs : enumeration value =" b" />
8+ </xs : restriction >
9+ </xs : simpleType >
10+ </xs : schema >
Original file line number Diff line number Diff line change @@ -383,10 +383,21 @@ public override CodeTypeDeclaration Generate()
383383 keyProperty . IsKey = true ;
384384 }
385385
386- foreach ( var property in Properties )
387- property . AddMembersTo ( classDeclaration , Configuration . EnableDataBinding ) ;
388-
389- if ( IsMixed && ( BaseClass == null || ( BaseClass is ClassModel && ! AllBaseClasses . Any ( b => b . IsMixed ) ) ) )
386+ foreach ( var property in Properties . GroupBy ( x => x . Name ) )
387+ {
388+ var propertyIndex = 0 ;
389+ foreach ( var p in property )
390+ {
391+ if ( propertyIndex > 0 )
392+ {
393+ p . Name += $ "_{ propertyIndex } ";
394+ }
395+ p . AddMembersTo ( classDeclaration , Configuration . EnableDataBinding ) ;
396+ propertyIndex ++ ;
397+ }
398+ }
399+
400+ if ( IsMixed && ( BaseClass == null || ( BaseClass is ClassModel && ! AllBaseClasses . Any ( b => b . IsMixed ) ) ) )
390401 {
391402 var text = new CodeMemberField ( typeof ( string ) , "Text" ) ;
392403 // hack to generate automatic property
You can’t perform that action at this time.
0 commit comments