@@ -68,7 +68,7 @@ public override bool VisitClassDecl(Class @class)
68
68
69
69
protected virtual IEnumerable < Property > GenerateProperties ( Class @class )
70
70
{
71
- var newProperties = new List < Property > ( ) ;
71
+ var properties = new List < Property > ( ) ;
72
72
foreach ( Method method in @class . Methods . Where (
73
73
m => ! m . IsConstructor && ! m . IsDestructor && ! m . IsOperator && m . IsGenerated &&
74
74
m . SynthKind != FunctionSynthKind . DefaultValueOverload &&
@@ -78,39 +78,29 @@ protected virtual IEnumerable<Property> GenerateProperties(Class @class)
78
78
if ( IsGetter ( method ) )
79
79
{
80
80
string name = GetPropertyName ( method . Name ) ;
81
- QualifiedType type = method . OriginalReturnType ;
82
- Property property = GetProperty ( method , name , type ) ;
83
- if ( ! property . HasGetter )
84
- {
85
- property . GetMethod = method ;
86
- property . QualifiedType = method . OriginalReturnType ;
87
- newProperties . Add ( property ) ;
88
- }
89
- else
90
- method . GenerationKind = GenerationKind . Generate ;
81
+ GetProperty ( properties , method , name , method . OriginalReturnType ) ;
91
82
continue ;
92
83
}
93
84
if ( IsSetter ( method ) )
94
85
{
95
86
string name = GetPropertyNameFromSetter ( method . Name ) ;
96
- QualifiedType type = method . Parameters . First ( p => p . Kind == ParameterKind . Regular ) . QualifiedType ;
97
- Property property = GetProperty ( method , name , type , true ) ;
98
- property . SetMethod = method ;
99
- newProperties . Add ( property ) ;
87
+ QualifiedType type = method . Parameters . First (
88
+ p => p . Kind == ParameterKind . Regular ) . QualifiedType ;
89
+ GetProperty ( properties , method , name , type , true ) ;
100
90
}
101
91
}
102
92
103
- return CleanUp ( @class , newProperties ) ;
93
+ return CleanUp ( @class , properties ) ;
104
94
}
105
95
106
- private IEnumerable < Property > CleanUp ( Class @class , List < Property > newProperties )
96
+ private IEnumerable < Property > CleanUp ( Class @class , List < Property > properties )
107
97
{
108
98
if ( ! Options . UsePropertyDetectionHeuristics )
109
- return newProperties ;
99
+ return properties ;
110
100
111
- for ( int i = newProperties . Count - 1 ; i >= 0 ; i -- )
101
+ for ( int i = properties . Count - 1 ; i >= 0 ; i -- )
112
102
{
113
- Property property = newProperties [ i ] ;
103
+ Property property = properties [ i ] ;
114
104
if ( property . HasSetter )
115
105
continue ;
116
106
@@ -124,47 +114,46 @@ private IEnumerable<Property> CleanUp(Class @class, List<Property> newProperties
124
114
{
125
115
property . GetMethod . GenerationKind = GenerationKind . Generate ;
126
116
@class . Properties . Remove ( property ) ;
127
- newProperties . RemoveAt ( i ) ;
117
+ properties . RemoveAt ( i ) ;
128
118
}
129
119
}
130
120
131
- return newProperties ;
121
+ return properties ;
132
122
}
133
123
134
- private static Property GetProperty ( Method method , string name ,
135
- QualifiedType type , bool isSetter = false )
124
+ private static void GetProperty ( List < Property > properties , Method method ,
125
+ string name , QualifiedType type , bool isSetter = false )
136
126
{
137
127
Type underlyingType = GetUnderlyingType ( type ) ;
138
128
Class @class = ( Class ) method . Namespace ;
139
129
140
- Property property = @class . Properties . Find (
130
+ Property property = properties . Find (
141
131
p => p . Field == null &&
142
132
( ( ! isSetter && p . SetMethod ? . IsStatic == method . IsStatic ) ||
143
- ( isSetter && p . GetMethod ? . IsStatic == method . IsStatic ) ) &&
144
- ( ( p . HasGetter && GetUnderlyingType (
145
- p . GetMethod . OriginalReturnType ) . Equals ( underlyingType ) ) ||
146
- ( p . HasSetter && GetUnderlyingType (
147
- p . SetMethod . Parameters [ 0 ] . QualifiedType ) . Equals ( underlyingType ) ) ) &&
148
- Match ( p , name ) ) ??
149
- new Property { Name = name , QualifiedType = type } ;
150
-
151
- if ( property . Namespace == null )
152
- {
153
- property . Namespace = method . Namespace ;
154
- property . Access = method . Access ;
155
- @class . Properties . Add ( property ) ;
156
- }
133
+ ( isSetter && p . GetMethod ? . IsStatic == method . IsStatic ) ) &&
134
+ ( ( p . HasGetter && GetUnderlyingType (
135
+ p . GetMethod . OriginalReturnType ) . Equals ( underlyingType ) ) ||
136
+ ( p . HasSetter && GetUnderlyingType (
137
+ p . SetMethod . Parameters [ 0 ] . QualifiedType ) . Equals ( underlyingType ) ) ) &&
138
+ Match ( p , name ) ) ;
139
+
140
+ if ( property == null )
141
+ properties . Add ( property = new Property { Name = name , QualifiedType = type } ) ;
142
+
143
+ if ( isSetter )
144
+ property . SetMethod = method ;
157
145
else
158
146
{
159
- property . Access = ( AccessSpecifier ) Math . Max (
160
- ( int ) ( property . GetMethod ?? property . SetMethod ) . Access ,
161
- ( int ) method . Access ) ;
147
+ property . GetMethod = method ;
148
+ property . QualifiedType = method . OriginalReturnType ;
162
149
}
163
150
164
- method . GenerationKind = GenerationKind . Internal ;
151
+ property . Access = ( AccessSpecifier ) Math . Max (
152
+ ( int ) ( property . GetMethod ?? property . SetMethod ) . Access ,
153
+ ( int ) method . Access ) ;
154
+
165
155
if ( method . ExplicitInterfaceImpl != null )
166
156
property . ExplicitInterfaceImpl = method . ExplicitInterfaceImpl ;
167
- return property ;
168
157
}
169
158
170
159
private static bool Match ( Property property , string name )
@@ -198,37 +187,30 @@ private static string RemovePrefix(string identifier)
198
187
char . ToLowerInvariant ( name [ 2 ] ) + name . Substring ( 3 ) : name ;
199
188
}
200
189
201
- private static void ProcessProperties ( Class @class , IEnumerable < Property > newProperties )
190
+ private static void ProcessProperties ( Class @class , IEnumerable < Property > properties )
202
191
{
203
- foreach ( Property property in newProperties )
192
+ foreach ( Property property in properties )
204
193
{
205
194
ProcessOverridden ( @class , property ) ;
206
195
207
196
if ( ! property . HasGetter )
208
- {
209
- if ( property . HasSetter )
210
- property . SetMethod . GenerationKind = GenerationKind . Generate ;
211
- @class . Properties . Remove ( property ) ;
212
197
continue ;
213
- }
214
198
if ( ! property . HasSetter &&
215
199
@class . GetOverloads ( property . GetMethod ) . Any (
216
200
m => m != property . GetMethod && ! m . Ignore ) )
217
- {
218
- property . GetMethod . GenerationKind = GenerationKind . Generate ;
219
- @class . Properties . Remove ( property ) ;
220
201
continue ;
221
- }
222
202
223
- Property conflict = newProperties . LastOrDefault (
203
+ Property conflict = properties . LastOrDefault (
224
204
p => p . Name == property . Name && p != property &&
225
205
p . ExplicitInterfaceImpl == property . ExplicitInterfaceImpl ) ;
226
- if ( conflict != null && conflict . GetMethod != null )
227
- {
228
- conflict . GetMethod . GenerationKind = GenerationKind . Generate ;
206
+ if ( conflict ? . GetMethod != null )
229
207
conflict . GetMethod = null ;
230
- }
231
208
209
+ property . GetMethod . GenerationKind = GenerationKind . Internal ;
210
+ if ( property . SetMethod != null )
211
+ property . SetMethod . GenerationKind = GenerationKind . Internal ;
212
+ property . Namespace = @class ;
213
+ @class . Properties . Add ( property ) ;
232
214
RenameConflictingMethods ( @class , property ) ;
233
215
CombineComments ( property ) ;
234
216
}
@@ -243,24 +225,14 @@ private static void ProcessOverridden(Class @class, Property property)
243
225
if ( baseProperty == null )
244
226
{
245
227
if ( property . HasSetter )
246
- {
247
- property . SetMethod . GenerationKind = GenerationKind . Generate ;
248
228
property . SetMethod = null ;
249
- }
250
229
else
251
- {
252
- property . GetMethod . GenerationKind = GenerationKind . Generate ;
253
230
property . GetMethod = null ;
254
- }
255
231
}
256
232
else if ( ! property . HasGetter && baseProperty . HasSetter )
257
233
property . GetMethod = baseProperty . GetMethod ;
258
234
else if ( ! property . HasSetter || ! baseProperty . HasSetter )
259
- {
260
- if ( property . HasSetter )
261
- property . SetMethod . GenerationKind = GenerationKind . Generate ;
262
235
property . SetMethod = baseProperty . SetMethod ;
263
- }
264
236
}
265
237
266
238
private static void RenameConflictingMethods ( Class @class , Property property )
0 commit comments