1
1
using Compentio . SourceConfig . Context ;
2
+ using Compentio . SourceConfig . Extensions ;
2
3
using Microsoft . CodeAnalysis ;
3
4
using Microsoft . CodeAnalysis . CSharp ;
4
5
using Microsoft . CodeAnalysis . Text ;
@@ -66,18 +67,18 @@ public class {_configurationFileContext.ClassName}
66
67
if ( value is JsonElement element && element . ValueKind == JsonValueKind . Array )
67
68
{
68
69
var propertyType = GetPropertyTypeName ( element . EnumerateArray ( ) . FirstOrDefault ( ) ) ;
69
- sourceBuilder . Append ( $ "public IEnumerable<{ propertyType } > { FormatPropertyName ( key ) } {{ get; set; }}") ;
70
+ sourceBuilder . Append ( $ "public IEnumerable<{ propertyType } > { key . FromatPropertyName ( ) } {{ get; set; }}") ;
70
71
}
71
72
else
72
73
{
73
- sourceBuilder . Append ( $ "public string { FormatPropertyName ( key ) } {{ get; set; }}") ;
74
+ sourceBuilder . Append ( $ "public string { key . FromatPropertyName ( ) } {{ get; set; }}") ;
74
75
}
75
76
}
76
77
77
78
foreach ( var item in _configurationFileContext . ConfigClasses )
78
79
{
79
80
var key = item . Key ;
80
- sourceBuilder . Append ( $ "public { FormatPropertyName ( key ) } { FormatPropertyName ( key ) } {{ get; set; }}") ;
81
+ sourceBuilder . Append ( $ "public { key . FromatPropertyName ( ) } { key . FromatPropertyName ( ) } {{ get; set; }}") ;
81
82
}
82
83
83
84
sourceBuilder . Append ( "}" ) ;
@@ -94,14 +95,15 @@ private void BuildConfigClass(KeyValuePair<string, object> classInfo, StringBuil
94
95
{
95
96
var nestedClasses = new StringBuilder ( ) ;
96
97
97
- stringBuilder . Append ( $ "public class { classInfo . Key } ") ;
98
+ stringBuilder . Append ( "[ExcludeFromCodeCoverage]" ) ;
99
+ stringBuilder . Append ( $ "public class { classInfo . Key . FromatClassName ( ) } ") ;
98
100
stringBuilder . Append ( "{" ) ;
99
101
100
102
foreach ( var item in ( Dictionary < string , object > ) classInfo . Value )
101
103
{
102
104
if ( item . Value is Dictionary < string , object > )
103
105
{
104
- stringBuilder . Append ( $ "public { item . Key } { FormatPropertyName ( item . Key ) } {{ get; set; }}") ;
106
+ stringBuilder . Append ( $ "public { item . Key } { item . Key . FromatPropertyName ( ) } {{ get; set; }}") ;
105
107
BuildConfigClass ( item , nestedClasses ) ;
106
108
}
107
109
else
@@ -110,11 +112,11 @@ private void BuildConfigClass(KeyValuePair<string, object> classInfo, StringBuil
110
112
var propertyType = GetPropertyTypeName ( prop ) ;
111
113
if ( prop . ValueKind == JsonValueKind . Array )
112
114
{
113
- stringBuilder . Append ( $ "public IEnumerable<{ propertyType } > { FormatPropertyName ( item . Key ) } {{ get; set; }}") ;
115
+ stringBuilder . Append ( $ "public IEnumerable<{ propertyType } > { item . Key . FromatPropertyName ( ) } {{ get; set; }}") ;
114
116
}
115
117
else
116
118
{
117
- stringBuilder . Append ( $ "public { propertyType } { FormatPropertyName ( item . Key ) } {{ get; set; }}") ;
119
+ stringBuilder . Append ( $ "public { propertyType } { item . Key . FromatPropertyName ( ) } {{ get; set; }}") ;
118
120
}
119
121
}
120
122
}
@@ -132,13 +134,5 @@ private string GetPropertyTypeName(JsonElement value)
132
134
_ => "string" ,
133
135
} ;
134
136
}
135
-
136
- private string FormatPropertyName ( string origin )
137
- {
138
- var underscore = "_" ;
139
- return origin
140
- . Replace ( "." , underscore )
141
- . Replace ( "$" , underscore ) ;
142
- }
143
137
}
144
138
}
0 commit comments