1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Linq ;
44using Mono . Cecil ;
@@ -55,7 +55,7 @@ private static IEnumerable<AttachedEventReference> GetAttachedEvents(TypeDefinit
5555
5656 private static bool IsAttachedEvent ( FieldDefinition field , Dictionary < string , IEnumerable < MethodDefinition > > methods )
5757 {
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
5959 if ( ! field . Name . EndsWith ( EventConst ) )
6060 return false ;
6161 var addMethodName = $ "Add{ GetEventName ( field . Name ) } Handler";
@@ -92,11 +92,11 @@ private static bool AreAttachedEventMethodParameters(Collection<ParameterDefinit
9292 return false ;
9393 return
9494 // 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
100100 && IsAttachedEventHandler ( parameters [ 1 ] . ParameterType ) ;
101101 }
102102
@@ -119,18 +119,18 @@ private static IEnumerable<AttachedPropertyReference> GetAttachedProperties(Type
119119 yield return new AttachedPropertyReference ( field ) ;
120120 }
121121
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 ) ;
128128 }
129129 }
130130
131131 private static bool IsAttachedProperty ( FieldDefinition field , Dictionary < string , IEnumerable < MethodDefinition > > methods )
132132 {
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
134134 // https://github.com/mono/api-doc-tools/issues/63#issuecomment-328995418
135135 if ( ! field . Name . EndsWith ( PropertyConst , StringComparison . Ordinal ) )
136136 return false ;
@@ -155,30 +155,30 @@ private static bool IsAttachedProperty(FieldDefinition field, Dictionary<string,
155155 && ( ( methods . ContainsKey ( getMethodName ) && methods [ getMethodName ] . Any ( IsAttachedPropertyGetMethod ) )
156156 || ( methods . ContainsKey ( setMethodName ) && methods [ setMethodName ] . Any ( IsAttachedPropertySetMethod ) ) ) ;
157157
158- }
159-
158+ }
159+
160160 private static bool IsAttachedProperty ( PropertyDefinition property , Dictionary < string , IEnumerable < MethodDefinition > > methods )
161- {
162-
161+ {
162+
163163 if ( ! property . Name . EndsWith ( PropertyConst , StringComparison . Ordinal ) )
164164 return false ;
165- var propertyName = GetPropertyName ( property . Name ) ;
165+ var propertyName = GetPropertyName ( property . Name ) ;
166166 var getMethodName = $ "Get{ propertyName } ";
167167 var setMethodName = $ "Set{ propertyName } ";
168168
169169 var hasExistingProperty = property ? . DeclaringType ? . Properties . Any ( p => p . Name . Equals ( propertyName , StringComparison . Ordinal ) && GetCheckVisible ( p . Resolve ( ) ) ) ;
170170 var hasExistingField = property ? . DeclaringType ? . Fields . Any ( f => f . Name . Equals ( propertyName , StringComparison . Ordinal ) && GetCheckVisible ( f . Resolve ( ) ) ) ;
171171
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]
179179 && ( ( 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+
182182 }
183183
184184 private static bool IsAttachedPropertyGetMethod ( MethodDefinition method )
@@ -190,7 +190,7 @@ private static bool IsAttachedPropertyGetMethod(MethodDefinition method)
190190
191191 // The Get method takes one argument of type DependencyObject(or something IsAssignableTo(DependencyObject),
192192 && ( IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullName ) ||
193- IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
193+ IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinRT ) ||
194194 IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyObjectFullNameWinUI ) ) ;
195195 }
196196
@@ -200,15 +200,15 @@ private static bool IsAttachedPropertySetMethod(MethodDefinition method)
200200
201201 // The first has type DependencyObject(or IsAssignableTo…),
202202 && ( 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 ) ||
205205 IsAssignableTo ( method . Parameters [ 0 ] . ParameterType , Consts . DependencyPropertyFullNameIInputElement ) ||
206206 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.
212212 && method . ReturnType . FullName == Consts . VoidFullName ;
213213 }
214214 #endregion
@@ -222,58 +222,58 @@ private static bool IsAssignableTo(TypeReference type, string targetTypeName)
222222 return type . FullName == targetTypeName ;
223223
224224 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+
240240 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 ;
260260 }
261261
262262 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+
271271 }
272272
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 ;
278278 }
279279}
0 commit comments