The following code in Test() should cause warnings to appear on MethodWithDataflow and MethodWithRequires because o is known to be DamOnTypeAccessesMembers which is annotated with DAMT.All, and is passed to RequiresAll, enforcing the requirement. The analyzer should recognize the pattern of Object.GetType() on a statically known type with DAM on the type.
Related to #93720
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]publicclassDamOnTypeAccessesMembers{[ExpectedWarning("IL2114",nameof(MethodWithDataflow),nameof(DynamicallyAccessedMembersAttribute),Tool.Trimmer|Tool.NativeAot,"")]publicvoidMethodWithDataflow([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]Typetype){}[RequiresDynamicCode("--MethodWithRequires--")][RequiresUnreferencedCode("--MethodWithRequires--")][RequiresAssemblyFiles("--MethodWithRequires--")][ExpectedWarning("IL2112","requires unreferenced code","--MethodWithRequires--",Tool.Trimmer|Tool.NativeAot,"")]publicvoidMethodWithRequires(){}publicstaticvoidTest(){varo=newDamOnTypeAccessesMembers();vart=o.GetType();t.RequiresAll();t.ToString();// This triggers the warnings in the analyzer, but not Object.GetType() on DamOnTypeAccessesMembers//typeof(DamOnTypeAccessesMembers).RequiresAll();}}
The following code in
Test()should cause warnings to appear onMethodWithDataflowandMethodWithRequiresbecauseois known to beDamOnTypeAccessesMemberswhich is annotated with DAMT.All, and is passed toRequiresAll, enforcing the requirement. The analyzer should recognize the pattern of Object.GetType() on a statically known type with DAM on the type.Related to #93720