@@ -205,106 +205,105 @@ void VerifyLinkingOfOtherAssemblies (AssemblyDefinition original)
205205
206206 try {
207207 foreach ( var assemblyName in checks . Keys ) {
208- using ( var linkedAssembly = ResolveLinkedAssembly ( assemblyName ) ) {
209- foreach ( var checkAttrInAssembly in checks [ assemblyName ] ) {
210- var attributeTypeName = checkAttrInAssembly . AttributeType . Name ;
211-
212- switch ( attributeTypeName ) {
213- case nameof ( KeptAllTypesAndMembersInAssemblyAttribute ) :
214- VerifyKeptAllTypesAndMembersInAssembly ( linkedAssembly ) ;
215- continue ;
216- case nameof ( KeptAttributeInAssemblyAttribute ) :
217- VerifyKeptAttributeInAssembly ( checkAttrInAssembly , linkedAssembly ) ;
218- continue ;
219- case nameof ( RemovedAttributeInAssembly ) :
220- VerifyRemovedAttributeInAssembly ( checkAttrInAssembly , linkedAssembly ) ;
221- continue ;
222- default :
223- break ;
224- }
225-
226- var expectedTypeName = checkAttrInAssembly . ConstructorArguments [ 1 ] . Value . ToString ( ) ;
227- TypeDefinition linkedType = linkedAssembly . MainModule . GetType ( expectedTypeName ) ;
228-
229- if ( linkedType == null && linkedAssembly . MainModule . HasExportedTypes ) {
230- ExportedType exportedType = linkedAssembly . MainModule . ExportedTypes
231- . FirstOrDefault ( exported => exported . FullName == expectedTypeName ) ;
232-
233- // Note that copied assemblies could have dangling references.
234- if ( exportedType != null && original . EntryPoint . DeclaringType . CustomAttributes . FirstOrDefault (
235- ca => ca . AttributeType . Name == nameof ( RemovedAssemblyAttribute )
236- && ca . ConstructorArguments [ 0 ] . Value . ToString ( ) == exportedType . Scope . Name + ".dll" ) != null )
237- continue ;
238-
239- linkedType = exportedType ? . Resolve ( ) ;
240- }
208+ var linkedAssembly = ResolveLinkedAssembly ( assemblyName ) ;
209+ foreach ( var checkAttrInAssembly in checks [ assemblyName ] ) {
210+ var attributeTypeName = checkAttrInAssembly . AttributeType . Name ;
211+
212+ switch ( attributeTypeName ) {
213+ case nameof ( KeptAllTypesAndMembersInAssemblyAttribute ) :
214+ VerifyKeptAllTypesAndMembersInAssembly ( linkedAssembly ) ;
215+ continue ;
216+ case nameof ( KeptAttributeInAssemblyAttribute ) :
217+ VerifyKeptAttributeInAssembly ( checkAttrInAssembly , linkedAssembly ) ;
218+ continue ;
219+ case nameof ( RemovedAttributeInAssembly ) :
220+ VerifyRemovedAttributeInAssembly ( checkAttrInAssembly , linkedAssembly ) ;
221+ continue ;
222+ default :
223+ break ;
224+ }
241225
242- switch ( attributeTypeName ) {
243- case nameof ( RemovedTypeInAssemblyAttribute ) :
244- if ( linkedType != null )
245- Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been removed") ;
246- GetOriginalTypeFromInAssemblyAttribute ( checkAttrInAssembly ) ;
247- break ;
248- case nameof ( KeptTypeInAssemblyAttribute ) :
249- if ( linkedType == null )
250- Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
251- break ;
252- case nameof ( RemovedInterfaceOnTypeInAssemblyAttribute ) :
253- if ( linkedType == null )
254- Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
255- VerifyRemovedInterfaceOnTypeInAssembly ( checkAttrInAssembly , linkedType ) ;
256- break ;
257- case nameof ( KeptInterfaceOnTypeInAssemblyAttribute ) :
258- if ( linkedType == null )
259- Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
260- VerifyKeptInterfaceOnTypeInAssembly ( checkAttrInAssembly , linkedType ) ;
261- break ;
262- case nameof ( RemovedMemberInAssemblyAttribute ) :
263- if ( linkedType == null )
264- continue ;
226+ var expectedTypeName = checkAttrInAssembly . ConstructorArguments [ 1 ] . Value . ToString ( ) ;
227+ TypeDefinition linkedType = linkedAssembly . MainModule . GetType ( expectedTypeName ) ;
265228
266- VerifyRemovedMemberInAssembly ( checkAttrInAssembly , linkedType ) ;
267- break ;
268- case nameof ( KeptBaseOnTypeInAssemblyAttribute ) :
269- if ( linkedType == null )
270- Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
271- VerifyKeptBaseOnTypeInAssembly ( checkAttrInAssembly , linkedType ) ;
272- break ;
273- case nameof ( KeptMemberInAssemblyAttribute ) :
274- if ( linkedType == null )
275- Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
229+ if ( linkedType == null && linkedAssembly . MainModule . HasExportedTypes ) {
230+ ExportedType exportedType = linkedAssembly . MainModule . ExportedTypes
231+ . FirstOrDefault ( exported => exported . FullName == expectedTypeName ) ;
276232
277- VerifyKeptMemberInAssembly ( checkAttrInAssembly , linkedType ) ;
278- break ;
279- case nameof ( RemovedForwarderAttribute ) :
280- if ( linkedAssembly . MainModule . ExportedTypes . Any ( l => l . Name == expectedTypeName ) )
281- Assert . Fail ( $ "Forwarder ` { expectedTypeName } ' should have been removed" ) ;
233+ // Note that copied assemblies could have dangling references.
234+ if ( exportedType != null && original . EntryPoint . DeclaringType . CustomAttributes . FirstOrDefault (
235+ ca => ca . AttributeType . Name == nameof ( RemovedAssemblyAttribute )
236+ && ca . ConstructorArguments [ 0 ] . Value . ToString ( ) == exportedType . Scope . Name + ".dll" ) != null )
237+ continue ;
282238
283- break ;
239+ linkedType = exportedType ? . Resolve ( ) ;
240+ }
284241
285- case nameof ( RemovedAssemblyReferenceAttribute ) :
286- Assert . False ( linkedAssembly . MainModule . AssemblyReferences . Any ( l => l . Name == expectedTypeName ) ,
287- $ "AssemblyRef '{ expectedTypeName } ' should have been removed") ;
288- break ;
242+ switch ( attributeTypeName ) {
243+ case nameof ( RemovedTypeInAssemblyAttribute ) :
244+ if ( linkedType != null )
245+ Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been removed") ;
246+ GetOriginalTypeFromInAssemblyAttribute ( checkAttrInAssembly ) ;
247+ break ;
248+ case nameof ( KeptTypeInAssemblyAttribute ) :
249+ if ( linkedType == null )
250+ Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
251+ break ;
252+ case nameof ( RemovedInterfaceOnTypeInAssemblyAttribute ) :
253+ if ( linkedType == null )
254+ Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
255+ VerifyRemovedInterfaceOnTypeInAssembly ( checkAttrInAssembly , linkedType ) ;
256+ break ;
257+ case nameof ( KeptInterfaceOnTypeInAssemblyAttribute ) :
258+ if ( linkedType == null )
259+ Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
260+ VerifyKeptInterfaceOnTypeInAssembly ( checkAttrInAssembly , linkedType ) ;
261+ break ;
262+ case nameof ( RemovedMemberInAssemblyAttribute ) :
263+ if ( linkedType == null )
264+ continue ;
289265
290- case nameof ( KeptResourceInAssemblyAttribute ) :
291- VerifyKeptResourceInAssembly ( checkAttrInAssembly ) ;
292- break ;
293- case nameof ( RemovedResourceInAssemblyAttribute ) :
294- VerifyRemovedResourceInAssembly ( checkAttrInAssembly ) ;
295- break ;
296- case nameof ( KeptReferencesInAssemblyAttribute ) :
297- VerifyKeptReferencesInAssembly ( checkAttrInAssembly ) ;
298- break ;
299- case nameof ( ExpectedInstructionSequenceOnMemberInAssemblyAttribute ) :
300- if ( linkedType == null )
301- Assert . Fail ( $ "Type `{ expectedTypeName } ` should have been kept") ;
302- VerifyExpectedInstructionSequenceOnMemberInAssembly ( checkAttrInAssembly , linkedType ) ;
303- break ;
304- default :
305- UnhandledOtherAssemblyAssertion ( expectedTypeName , checkAttrInAssembly , linkedType ) ;
306- break ;
307- }
266+ VerifyRemovedMemberInAssembly ( checkAttrInAssembly , linkedType ) ;
267+ break ;
268+ case nameof ( KeptBaseOnTypeInAssemblyAttribute ) :
269+ if ( linkedType == null )
270+ Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
271+ VerifyKeptBaseOnTypeInAssembly ( checkAttrInAssembly , linkedType ) ;
272+ break ;
273+ case nameof ( KeptMemberInAssemblyAttribute ) :
274+ if ( linkedType == null )
275+ Assert . Fail ( $ "Type `{ expectedTypeName } ' should have been kept") ;
276+
277+ VerifyKeptMemberInAssembly ( checkAttrInAssembly , linkedType ) ;
278+ break ;
279+ case nameof ( RemovedForwarderAttribute ) :
280+ if ( linkedAssembly . MainModule . ExportedTypes . Any ( l => l . Name == expectedTypeName ) )
281+ Assert . Fail ( $ "Forwarder `{ expectedTypeName } ' should have been removed") ;
282+
283+ break ;
284+
285+ case nameof ( RemovedAssemblyReferenceAttribute ) :
286+ Assert . False ( linkedAssembly . MainModule . AssemblyReferences . Any ( l => l . Name == expectedTypeName ) ,
287+ $ "AssemblyRef '{ expectedTypeName } ' should have been removed") ;
288+ break ;
289+
290+ case nameof ( KeptResourceInAssemblyAttribute ) :
291+ VerifyKeptResourceInAssembly ( checkAttrInAssembly ) ;
292+ break ;
293+ case nameof ( RemovedResourceInAssemblyAttribute ) :
294+ VerifyRemovedResourceInAssembly ( checkAttrInAssembly ) ;
295+ break ;
296+ case nameof ( KeptReferencesInAssemblyAttribute ) :
297+ VerifyKeptReferencesInAssembly ( checkAttrInAssembly ) ;
298+ break ;
299+ case nameof ( ExpectedInstructionSequenceOnMemberInAssemblyAttribute ) :
300+ if ( linkedType == null )
301+ Assert . Fail ( $ "Type `{ expectedTypeName } ` should have been kept") ;
302+ VerifyExpectedInstructionSequenceOnMemberInAssembly ( checkAttrInAssembly , linkedType ) ;
303+ break ;
304+ default :
305+ UnhandledOtherAssemblyAssertion ( expectedTypeName , checkAttrInAssembly , linkedType ) ;
306+ break ;
308307 }
309308 }
310309 }
0 commit comments