@@ -91,25 +91,24 @@ public void DoubleAttributedElements (string assemblyPath)
9191 return ;
9292 }
9393
94- var doubleAttributed = new List < string > ( ) ;
94+ var doubleAttributed = new List < string > ( ) ;
9595 foreach ( var type in Helper . FilterTypes ( assembly , a => HasAnyAvailabilityAttribute ( a ) ) ) {
9696 var platformCount = new Dictionary < string , int > ( ) ;
9797 foreach ( var attribute in type . CustomAttributes . Where ( a => IsAvailabilityAttribute ( a ) ) ) {
9898 var kind = FindAvailabilityKind ( attribute ) ;
9999 if ( kind is not null ) {
100- string key = $ "{ attribute . AttributeType . Name } -{ kind } ";
100+ string key = $ "{ attribute . AttributeType . Name } -{ kind } ";
101101 if ( platformCount . ContainsKey ( key ) ) {
102- platformCount [ key ] += 1 ;
103- }
104- else {
105- platformCount [ key ] = 1 ;
102+ platformCount [ key ] += 1 ;
103+ } else {
104+ platformCount [ key ] = 1 ;
106105 }
107106 }
108107 }
109108 foreach ( var ( kind , count ) in platformCount ) {
110109 // AVFoundation.AVMetadataIdentifiers uses an old pattern of a parent
111110 // class and many child classes with constants.
112- if ( type . ToString ( ) == "AVFoundation.AVMetadataIdentifiers" ) {
111+ if ( type . ToString ( ) == "AVFoundation.AVMetadataIdentifiers" ) {
113112 continue ;
114113 }
115114 if ( count != 1 ) {
@@ -133,13 +132,12 @@ void CheckAllPlatformsOnParent (ICustomAttributeProvider item, string fullName,
133132
134133 var myAvailability = GetAvailabilityAttributes ( item ) ;
135134 if ( ! FirstContainsAllOfSecond ( myAvailability , parentAvailability ) ) {
136- DebugPrint ( fullName , parentAvailability , myAvailability ) ;
137- found . Add ( fullName ) ;
135+ DebugPrint ( fullName , parentAvailability , myAvailability ) ;
136+ found . Add ( fullName ) ;
138137 }
139138 }
140139
141- public class PlatformClaimInfo
142- {
140+ public class PlatformClaimInfo {
143141 public HashSet < string > MentionedPlatforms { get ; set ; } // Mentioned in both Supported and Unsupported contexts
144142 public HashSet < string > ClaimedPlatforms { get ; set ; } // Mentioned only in Supported contexts
145143
@@ -192,59 +190,58 @@ public void FindSupportedOnElementsThatDoNotExistInThatAssembly ()
192190 foreach ( var module in assembly . Modules ) {
193191 foreach ( var type in module . Types ) {
194192 foreach ( var member in GetAllTypeMembers ( type ) ) {
195- var mentionedPlatforms = GetAvailabilityAttributes ( member ) . ToList ( ) ;
196- if ( mentionedPlatforms . Any ( ) ) {
197- var claimedPlatforms = GetSupportedAvailabilityAttributes ( member ) . ToList ( ) ;
193+ var mentionedPlatforms = GetAvailabilityAttributes ( member ) . ToList ( ) ;
194+ if ( mentionedPlatforms . Any ( ) ) {
195+ var claimedPlatforms = GetSupportedAvailabilityAttributes ( member ) . ToList ( ) ;
198196 string key = GetMemberLookupKey ( member ) ;
199197 if ( ! harvestedInfo . ContainsKey ( key ) ) {
200- harvestedInfo [ key ] = new Dictionary < string , PlatformClaimInfo > ( ) ;
198+ harvestedInfo [ key ] = new Dictionary < string , PlatformClaimInfo > ( ) ;
201199 }
202200 var claimInfo = new PlatformClaimInfo ( mentionedPlatforms , claimedPlatforms ) ;
203- if ( harvestedInfo [ key ] . ContainsKey ( currentPlatform ) ) {
204- harvestedInfo [ key ] [ currentPlatform ] . UnionWith ( claimInfo ) ;
205- }
206- else {
207- harvestedInfo [ key ] [ currentPlatform ] = claimInfo ;
201+ if ( harvestedInfo [ key ] . ContainsKey ( currentPlatform ) ) {
202+ harvestedInfo [ key ] [ currentPlatform ] . UnionWith ( claimInfo ) ;
203+ } else {
204+ harvestedInfo [ key ] [ currentPlatform ] = claimInfo ;
208205 }
209206 }
210207 }
211208 }
212209 }
213210 }
214-
211+
215212 // Now walk every item found above and check two things:
216- var attributesWereCompiledOut = new List < string > ( ) ;
217- var doesNotExistWhereClaimed = new List < string > ( ) ;
213+ var attributesWereCompiledOut = new List < string > ( ) ;
214+ var doesNotExistWhereClaimed = new List < string > ( ) ;
218215 foreach ( var ( member , info ) in harvestedInfo ) {
219216 // 1. All platforms match in count of mentioned (we did not conditionally compile out attributes)
220- int expectedPlatformCount = info . First ( ) . Value . MentionedPlatforms . Count ( ) ;
221- if ( info . Any ( i => i . Value . MentionedPlatforms . Count ( ) != expectedPlatformCount ) ) {
222- if ( IgnoreElementsThatDoNotExistInThatAssembly ( member ) ) {
223- continue ;
224- }
225- string detailedPlatformBreakdown = string . Join ( "\n " , info . Select ( x => ( $ "Assembly { x . Key } => { x . Value } ") ) ) ;
226- string errorMessage = $ "{ member } did not have the same number of SupportedOSPlatformAttribute in every assembly:\n { detailedPlatformBreakdown } ";
227- attributesWereCompiledOut . Add ( errorMessage ) ;
217+ int expectedPlatformCount = info . First ( ) . Value . MentionedPlatforms . Count ( ) ;
218+ if ( info . Any ( i => i . Value . MentionedPlatforms . Count ( ) != expectedPlatformCount ) ) {
219+ if ( IgnoreElementsThatDoNotExistInThatAssembly ( member ) ) {
220+ continue ;
221+ }
222+ string detailedPlatformBreakdown = string . Join ( "\n " , info . Select ( x => ( $ "Assembly { x . Key } => { x . Value } ") ) ) ;
223+ string errorMessage = $ "{ member } did not have the same number of SupportedOSPlatformAttribute in every assembly:\n { detailedPlatformBreakdown } ";
224+ attributesWereCompiledOut . Add ( errorMessage ) ;
228225#if DEBUG
229- Console . Error . WriteLine ( errorMessage ) ;
226+ Console . Error . WriteLine ( errorMessage ) ;
230227#endif
231228 }
232229
233230
234231 // 2. For each supported attribute claim exist, that it exists on that platform
235232 // Since we know each platform claims are now equal, just use the first one
236- var claimedPlatforms = info . First ( ) . Value . ClaimedPlatforms ;
233+ var claimedPlatforms = info . First ( ) . Value . ClaimedPlatforms ;
237234 foreach ( var platform in claimedPlatforms ) {
238235 if ( ! info . ContainsKey ( platform ) ) {
239236 if ( IgnoreElementsThatDoNotExistInThatAssembly ( member ) ) {
240237 continue ;
241238 }
242- string detailedPlatformBreakdown = string . Join ( "\n " , info . Select ( x => ( $ "Assembly { x . Key } => Declares ({ string . Join ( " " , x . Value ) } )") ) ) ;
239+ string detailedPlatformBreakdown = string . Join ( "\n " , info . Select ( x => ( $ "Assembly { x . Key } => Declares ({ string . Join ( " " , x . Value ) } )") ) ) ;
243240 string errorMessage = $ "{ member } was not found on { platform } despite being declared supported there.";
244241 doesNotExistWhereClaimed . Add ( errorMessage ) ;
245242#if DEBUG
246243 Console . Error . WriteLine ( errorMessage ) ;
247- #endif
244+ #endif
248245 }
249246 }
250247 }
@@ -260,7 +257,7 @@ static bool IgnoreElementsThatDoNotExistInThatAssembly (string member)
260257 return true ;
261258 }
262259 // QuickLook is aliased with QuickLookUI on some platforms
263- if ( member . StartsWith ( "QuickLook" ) ) {
260+ if ( member . StartsWith ( "QuickLook" ) ) {
264261 return true ;
265262 }
266263 // These two types are defined with non-trivial define magic and one platform doesn't necessarily have
@@ -275,7 +272,7 @@ static bool IgnoreElementsThatDoNotExistInThatAssembly (string member)
275272 return true ;
276273 }
277274 // Generator Bug - Protocol inline with different attribute bug
278- if ( member . StartsWith ( "SceneKit.SCNLayer" ) ||
275+ if ( member . StartsWith ( "SceneKit.SCNLayer" ) ||
279276 member . StartsWith ( "AVFoundation.AVAudioSession" ) ) {
280277 return true ;
281278 }
@@ -459,7 +456,7 @@ static string GetMemberLookupKey (IMemberDefinition member)
459456 // Members of xkit and other places conditionally inline and include members in one of two namespaces
460457 // based upon platform assembly. Cludge them to the same key, so we don't mistakenly think members are missing
461458 // from some platforms
462- return $ "{ member . DeclaringType . FullName } .{ member . Name } ". Replace ( "AppKit" , "Kit" ) . Replace ( "UIKit" , "Kit" ) ;
459+ return $ "{ member . DeclaringType . FullName } .{ member . Name } ". Replace ( "AppKit" , "Kit" ) . Replace ( "UIKit" , "Kit" ) ;
463460 }
464461
465462 IEnumerable < IMemberDefinition > GetAllTypeMembers ( TypeDefinition type )
@@ -525,7 +522,7 @@ void CheckCurrentPlatformIncludedIfAny (ICustomAttributeProvider item, string pl
525522 if ( ! supportedAttributes . Any ( a => FindAvailabilityKind ( a ) == platformName ) ) {
526523#if DEBUG
527524 Console . WriteLine ( fullName ) ;
528- Console . WriteLine ( String . Join ( " " , supportedAttributes . Select ( x => FindAvailabilityKind ( x ) ) ) ) ;
525+ Console . WriteLine ( String . Join ( " " , supportedAttributes . Select ( x => FindAvailabilityKind ( x ) ) ) ) ;
529526 Console . WriteLine ( platformName ) ;
530527#endif
531528 found . Add ( fullName ) ;
@@ -617,7 +614,7 @@ IEnumerable<string> GetAvailabilityAttributesCore (IEnumerable<CustomAttribute>
617614
618615 bool HasAnyAvailabilityAttribute ( ICustomAttributeProvider provider ) => provider . CustomAttributes . Any ( a => IsAvailabilityAttribute ( a ) ) ;
619616 bool HasAnySupportedAttribute ( ICustomAttributeProvider provider ) => provider . CustomAttributes . Any ( a => IsSupportedAttribute ( a ) ) ;
620-
617+
621618 bool IsAvailabilityAttribute ( CustomAttribute attribute ) => IsSupportedAttribute ( attribute ) || attribute . AttributeType . Name == "UnsupportedOSPlatformAttribute" ;
622619 bool IsSupportedAttribute ( CustomAttribute attribute ) => attribute . AttributeType . Name == "SupportedOSPlatformAttribute" ;
623620 }
0 commit comments