1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using Mono . Cecil ;
@@ -55,7 +55,7 @@ private static IEnumerable<AttachedEventReference> GetAttachedEvents(TypeDefinit
55
55
56
56
private static bool IsAttachedEvent ( FieldDefinition field , Dictionary < string , IEnumerable < MethodDefinition > > methods )
57
57
{
58
- // https://docs .microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-events-overview
58
+ // https://learn .microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-events-overview
59
59
if ( ! field . Name . EndsWith ( EventConst ) )
60
60
return false ;
61
61
var addMethodName = $ "Add{ GetEventName ( field . Name ) } Handler";
@@ -92,11 +92,11 @@ private static bool AreAttachedEventMethodParameters(Collection<ParameterDefinit
92
92
return false ;
93
93
return
94
94
// The first parameter is DependencyObject
95
- ( IsAssignableTo ( parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullName ) ||
96
- IsAssignableTo ( parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
97
- IsAssignableTo ( parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinUI ) )
98
-
99
- // The second parameter is the handler to add/remove
95
+ ( IsAssignableTo ( parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullName ) ||
96
+ IsAssignableTo ( parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
97
+ IsAssignableTo ( parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinUI ) )
98
+
99
+ // The second parameter is the handler to add/remove
100
100
&& IsAttachedEventHandler ( parameters [ 1 ] . ParameterType ) ;
101
101
}
102
102
@@ -119,18 +119,18 @@ private static IEnumerable<AttachedPropertyReference> GetAttachedProperties(Type
119
119
yield return new AttachedPropertyReference ( field ) ;
120
120
}
121
121
122
- foreach ( var property in type . Properties . Where ( t => t . PropertyType . FullName == Consts . DependencyPropertyFullName
123
- || t . PropertyType . FullName == Consts . DependencyPropertyFullNameWindowsXaml
124
- || t . PropertyType . FullName == Consts . DependencyPropertyFullNameMicrosoftXaml ) )
125
- {
126
- if ( IsAttachedProperty ( property , methods ) )
127
- yield return new AttachedPropertyReference ( property ) ;
122
+ foreach ( var property in type . Properties . Where ( t => t . PropertyType . FullName == Consts . DependencyPropertyFullName
123
+ || t . PropertyType . FullName == Consts . DependencyPropertyFullNameWindowsXaml
124
+ || t . PropertyType . FullName == Consts . DependencyPropertyFullNameMicrosoftXaml ) )
125
+ {
126
+ if ( IsAttachedProperty ( property , methods ) )
127
+ yield return new AttachedPropertyReference ( property ) ;
128
128
}
129
129
}
130
130
131
131
private static bool IsAttachedProperty ( FieldDefinition field , Dictionary < string , IEnumerable < MethodDefinition > > methods )
132
132
{
133
- // https://docs .microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview
133
+ // https://learn .microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview
134
134
// https://github.com/mono/api-doc-tools/issues/63#issuecomment-328995418
135
135
if ( ! field . Name . EndsWith ( PropertyConst , StringComparison . Ordinal ) )
136
136
return false ;
@@ -155,30 +155,30 @@ private static bool IsAttachedProperty(FieldDefinition field, Dictionary<string,
155
155
&& ( ( methods . ContainsKey ( getMethodName ) && methods [ getMethodName ] . Any ( IsAttachedPropertyGetMethod ) )
156
156
|| ( methods . ContainsKey ( setMethodName ) && methods [ setMethodName ] . Any ( IsAttachedPropertySetMethod ) ) ) ;
157
157
158
- }
159
-
158
+ }
159
+
160
160
private static bool IsAttachedProperty ( PropertyDefinition property , Dictionary < string , IEnumerable < MethodDefinition > > methods )
161
- {
162
-
161
+ {
162
+
163
163
if ( ! property . Name . EndsWith ( PropertyConst , StringComparison . Ordinal ) )
164
164
return false ;
165
- var propertyName = GetPropertyName ( property . Name ) ;
165
+ var propertyName = GetPropertyName ( property . Name ) ;
166
166
var getMethodName = $ "Get{ propertyName } ";
167
167
var setMethodName = $ "Set{ propertyName } ";
168
168
169
169
var hasExistingProperty = property ? . DeclaringType ? . Properties . Any ( p => p . Name . Equals ( propertyName , StringComparison . Ordinal ) && GetCheckVisible ( p . Resolve ( ) ) ) ;
170
170
var hasExistingField = property ? . DeclaringType ? . Fields . Any ( f => f . Name . Equals ( propertyName , StringComparison . Ordinal ) && GetCheckVisible ( f . Resolve ( ) ) ) ;
171
171
172
- return ! hasExistingProperty . IsTrue ( ) && ! hasExistingField . IsTrue ( ) &&
173
- // Class X has a static field of type DependencyProperty [Name]Property
174
- ( property . PropertyType . FullName == Consts . DependencyPropertyFullName || property . PropertyType . FullName == Consts . DependencyPropertyFullNameWindowsXaml
175
- || property . PropertyType . FullName == Consts . DependencyPropertyFullNameMicrosoftXaml )
176
-
177
-
178
- // Class X also has static methods with the following names: Get[Name] or Set[Name]
172
+ return ! hasExistingProperty . IsTrue ( ) && ! hasExistingField . IsTrue ( ) &&
173
+ // Class X has a static field of type DependencyProperty [Name]Property
174
+ ( property . PropertyType . FullName == Consts . DependencyPropertyFullName || property . PropertyType . FullName == Consts . DependencyPropertyFullNameWindowsXaml
175
+ || property . PropertyType . FullName == Consts . DependencyPropertyFullNameMicrosoftXaml )
176
+
177
+
178
+ // Class X also has static methods with the following names: Get[Name] or Set[Name]
179
179
&& ( ( methods . ContainsKey ( getMethodName ) && methods [ getMethodName ] . Any ( IsAttachedPropertyGetMethod ) )
180
- || ( methods . ContainsKey ( setMethodName ) && methods [ setMethodName ] . Any ( IsAttachedPropertySetMethod ) ) ) ;
181
-
180
+ || ( methods . ContainsKey ( setMethodName ) && methods [ setMethodName ] . Any ( IsAttachedPropertySetMethod ) ) ) ;
181
+
182
182
}
183
183
184
184
private static bool IsAttachedPropertyGetMethod ( MethodDefinition method )
@@ -190,7 +190,7 @@ private static bool IsAttachedPropertyGetMethod(MethodDefinition method)
190
190
191
191
// The Get method takes one argument of type DependencyObject(or something IsAssignableTo(DependencyObject),
192
192
&& ( IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullName ) ||
193
- IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
193
+ IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
194
194
IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinUI ) ) ;
195
195
}
196
196
@@ -200,15 +200,15 @@ private static bool IsAttachedPropertySetMethod(MethodDefinition method)
200
200
201
201
// The first has type DependencyObject(or IsAssignableTo…),
202
202
&& ( IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullName ) ||
203
- IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
204
- IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinUI ) ||
203
+ IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
204
+ IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinUI ) ||
205
205
IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyPropertyFullNameIInputElement ) ||
206
206
IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyPropertyFullNameObject ) )
207
-
208
- // the second has type dp.PropertyType (or IsAssignableTo…).
209
- // && IsAssignableTo(method.Parameters[1].ParameterType, "")
210
-
211
- // It returns void.
207
+
208
+ // the second has type dp.PropertyType (or IsAssignableTo…).
209
+ // && IsAssignableTo(method.Parameters[1].ParameterType, "")
210
+
211
+ // It returns void.
212
212
&& method . ReturnType . FullName == Consts . VoidFullName ;
213
213
}
214
214
#endregion
@@ -222,58 +222,58 @@ private static bool IsAssignableTo(TypeReference type, string targetTypeName)
222
222
return type . FullName == targetTypeName ;
223
223
224
224
return type . FullName == targetTypeName || IsAssignableTo ( typeDefenition . BaseType , targetTypeName ) ;
225
- }
226
-
227
- private static bool GetCheckVisible ( IMemberDefinition member )
228
- {
229
- if ( member == null )
230
- throw new ArgumentNullException ( "member" ) ;
231
- PropertyDefinition prop = member as PropertyDefinition ;
232
- if ( prop != null )
233
- return ChkPropertyVisible ( prop ) ;
234
- FieldDefinition field = member as FieldDefinition ;
235
- if ( field != null )
236
- return ChkFieldVisible ( field ) ;
237
- return false ;
238
- }
239
-
225
+ }
226
+
227
+ private static bool GetCheckVisible ( IMemberDefinition member )
228
+ {
229
+ if ( member == null )
230
+ throw new ArgumentNullException ( "member" ) ;
231
+ PropertyDefinition prop = member as PropertyDefinition ;
232
+ if ( prop != null )
233
+ return ChkPropertyVisible ( prop ) ;
234
+ FieldDefinition field = member as FieldDefinition ;
235
+ if ( field != null )
236
+ return ChkFieldVisible ( field ) ;
237
+ return false ;
238
+ }
239
+
240
240
private static bool ChkPropertyVisible ( PropertyDefinition property )
241
- {
242
- MethodDefinition method ;
243
- bool get_visible = false ;
244
- bool set_visible = false ;
245
-
246
- if ( ( method = property . GetMethod ) != null &&
247
- ( DocUtils . IsExplicitlyImplemented ( method ) ||
248
- ( ! method . IsPrivate && ! method . IsAssembly && ! method . IsFamilyAndAssembly ) ) )
249
- get_visible = true ;
250
-
251
- if ( ( method = property . SetMethod ) != null &&
252
- ( DocUtils . IsExplicitlyImplemented ( method ) ||
253
- ( ! method . IsPrivate && ! method . IsAssembly && ! method . IsFamilyAndAssembly ) ) )
254
- set_visible = true ;
255
-
256
- if ( ( set_visible == false ) && ( get_visible == false ) )
257
- return false ;
258
- else
259
- return true ;
241
+ {
242
+ MethodDefinition method ;
243
+ bool get_visible = false ;
244
+ bool set_visible = false ;
245
+
246
+ if ( ( method = property . GetMethod ) != null &&
247
+ ( DocUtils . IsExplicitlyImplemented ( method ) ||
248
+ ( ! method . IsPrivate && ! method . IsAssembly && ! method . IsFamilyAndAssembly ) ) )
249
+ get_visible = true ;
250
+
251
+ if ( ( method = property . SetMethod ) != null &&
252
+ ( DocUtils . IsExplicitlyImplemented ( method ) ||
253
+ ( ! method . IsPrivate && ! method . IsAssembly && ! method . IsFamilyAndAssembly ) ) )
254
+ set_visible = true ;
255
+
256
+ if ( ( set_visible == false ) && ( get_visible == false ) )
257
+ return false ;
258
+ else
259
+ return true ;
260
260
}
261
261
262
262
private static bool ChkFieldVisible ( FieldDefinition field )
263
- {
264
- TypeDefinition declType = ( TypeDefinition ) field . DeclaringType ;
265
-
266
- if ( declType . IsEnum && field . Name == "value__" )
267
- return false ; // This member of enums aren't documented.
268
-
269
- return field . IsPublic || field . IsFamily || field . IsFamilyOrAssembly ;
270
-
263
+ {
264
+ TypeDefinition declType = ( TypeDefinition ) field . DeclaringType ;
265
+
266
+ if ( declType . IsEnum && field . Name == "value__" )
267
+ return false ; // This member of enums aren't documented.
268
+
269
+ return field . IsPublic || field . IsFamily || field . IsFamilyOrAssembly ;
270
+
271
271
}
272
272
273
- }
274
- internal static class NBoolExtensions
275
- {
276
- public static bool IsTrue ( this Nullable < bool > value ) =>
277
- value . HasValue && value . Value ;
273
+ }
274
+ internal static class NBoolExtensions
275
+ {
276
+ public static bool IsTrue ( this Nullable < bool > value ) =>
277
+ value . HasValue && value . Value ;
278
278
}
279
279
}
0 commit comments