@@ -114,34 +114,62 @@ private static IEnumerable<AttachedPropertyReference> GetAttachedProperties(Type
114
114
if ( IsAttachedProperty ( field , methods ) )
115
115
yield return new AttachedPropertyReference ( field ) ;
116
116
}
117
+ foreach ( var prop in type . Properties )
118
+ {
119
+ if ( IsAttachedProperty ( prop , methods ) )
120
+ yield return new AttachedPropertyReference ( prop ) ;
121
+ }
117
122
}
118
123
119
124
private static bool IsAttachedProperty ( FieldDefinition field , Dictionary < string , IEnumerable < MethodDefinition > > methods )
120
125
{
121
- // https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview
122
- // https://github.com/mono/api-doc-tools/issues/63#issuecomment-328995418
123
- if ( ! field . Name . EndsWith ( PropertyConst , StringComparison . Ordinal ) )
126
+ string fieldName = field . Name ;
127
+ TypeReference fieldType = field . FieldType ;
128
+ TypeDefinition declaringType = field ? . DeclaringType ;
129
+ bool isPublic = field . IsPublic ;
130
+ bool isStatic = field . IsStatic ;
131
+ bool isInitOnly = field . IsInitOnly ;
132
+ return IsAttachedPropertyCore ( methods , fieldName , fieldType , declaringType , isPublic , isStatic , isInitOnly ) ;
133
+
134
+ }
135
+
136
+ private static bool IsAttachedProperty ( PropertyDefinition prop , Dictionary < string , IEnumerable < MethodDefinition > > methods )
137
+ {
138
+ string fieldName = prop . Name ;
139
+ TypeReference fieldType = prop . PropertyType ;
140
+ TypeDefinition declaringType = prop ? . DeclaringType ;
141
+ bool isPublic = prop . GetMethod . IsPublic ;
142
+ bool isStatic = prop . GetMethod . IsStatic ;
143
+ bool isInitOnly = prop . SetMethod == null || ! prop . SetMethod . IsPublic ;
144
+ return IsAttachedPropertyCore ( methods , fieldName , fieldType , declaringType , isPublic , isStatic , isInitOnly ) ;
145
+
146
+ }
147
+
148
+ private static bool IsAttachedPropertyCore ( Dictionary < string , IEnumerable < MethodDefinition > > methods , string fieldName , TypeReference fieldType , TypeDefinition declaringType , bool isPublic , bool isStatic , bool isInitOnly )
149
+ {
150
+ // https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview
151
+ // https://github.com/mono/api-doc-tools/issues/63#issuecomment-328995418
152
+ if ( ! fieldName . EndsWith ( PropertyConst , StringComparison . Ordinal ) )
124
153
return false ;
125
- var propertyName = GetPropertyName ( field . Name ) ;
154
+ var propertyName = GetPropertyName ( fieldName ) ;
126
155
var getMethodName = $ "Get{ propertyName } ";
127
156
var setMethodName = $ "Set{ propertyName } ";
128
157
129
- var hasExistingProperty = field ? . DeclaringType ? . Properties . Any ( p => p . Name . Equals ( propertyName , System . StringComparison . Ordinal ) ) ;
130
- var hasExistingField = field ? . DeclaringType ? . Fields . Any ( f => f . Name . Equals ( propertyName , System . StringComparison . Ordinal ) ) ;
158
+ var hasExistingProperty = declaringType ? . Properties . Any ( p => p . Name . Equals ( propertyName , System . StringComparison . Ordinal ) ) ;
159
+ var hasExistingField = declaringType ? . Fields . Any ( f => f . Name . Equals ( propertyName , System . StringComparison . Ordinal ) ) ;
131
160
132
- return ! hasExistingProperty . IsTrue ( ) && ! hasExistingField . IsTrue ( ) &&
133
- // Class X has a static field of type DependencyProperty [Name]Property
134
- ( field . FieldType . FullName == Consts . DependencyPropertyFullName || field . FieldType . FullName == Consts . DependencyPropertyFullNameXaml )
135
- && field . IsPublic
136
- && field . IsStatic
137
- && field . IsInitOnly
138
-
139
- // Class X also has static methods with the following names: Get[Name] and Set[Name]
161
+ return ! hasExistingProperty . IsTrue ( ) && ! hasExistingField . IsTrue ( ) &&
162
+ // Class X has a static field of type DependencyProperty [Name]Property
163
+ ( fieldType . FullName == Consts . DependencyPropertyFullName || fieldType . FullName == Consts . DependencyPropertyFullNameXaml )
164
+ && isPublic
165
+ && isStatic
166
+ && isInitOnly
167
+
168
+ // Class X also has static methods with the following names: Get[Name] and Set[Name]
140
169
&& ( ( methods . ContainsKey ( getMethodName ) && methods [ getMethodName ] . Any ( IsAttachedPropertyGetMethod ) )
141
- || ( methods . ContainsKey ( setMethodName ) && methods [ setMethodName ] . Any ( IsAttachedPropertySetMethod ) ) ) ;
142
-
143
- }
144
-
170
+ || ( methods . ContainsKey ( setMethodName ) && methods [ setMethodName ] . Any ( IsAttachedPropertySetMethod ) ) ) ;
171
+ }
172
+
145
173
private static bool IsAttachedPropertyGetMethod ( MethodDefinition method )
146
174
{
147
175
return method . Parameters . Count == 1
0 commit comments