1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System;
6 using System.Reflection;
7 using ILCompiler.Metadata;
8 using Internal.TypeSystem;
9 
10 namespace MetadataTransformTests
11 {
12     struct SingleFileMetadataPolicy : IMetadataPolicy
13     {
14         private static object s_lazyInitThreadSafetyLock = new object();
15         private ExplicitScopeAssemblyPolicyMixin _explicitScopePolicyMixin;
16 
GeneratesMetadataMetadataTransformTests.SingleFileMetadataPolicy17         public bool GeneratesMetadata(MethodDesc methodDef)
18         {
19             return true;
20         }
21 
GeneratesMetadataMetadataTransformTests.SingleFileMetadataPolicy22         public bool GeneratesMetadata(FieldDesc fieldDef)
23         {
24             return true;
25         }
26 
GeneratesMetadataMetadataTransformTests.SingleFileMetadataPolicy27         public bool GeneratesMetadata(MetadataType typeDef)
28         {
29             return true;
30         }
31 
IsBlockedMetadataTransformTests.SingleFileMetadataPolicy32         public bool IsBlocked(MetadataType typeDef)
33         {
34             if (typeDef.Name == "ICastable")
35                 return true;
36 
37             if (typeDef.HasCustomAttribute("System.Runtime.CompilerServices", "__BlockReflectionAttribute"))
38                 return true;
39 
40             return false;
41         }
42 
IsBlockedMetadataTransformTests.SingleFileMetadataPolicy43         public bool IsBlocked(MethodDesc method)
44         {
45             return IsBlocked((MetadataType)method.OwningType);
46         }
47 
GetModuleOfTypeMetadataTransformTests.SingleFileMetadataPolicy48         public ModuleDesc GetModuleOfType(MetadataType typeDef)
49         {
50             if (_explicitScopePolicyMixin == null)
51             {
52                 lock (s_lazyInitThreadSafetyLock)
53                 {
54                     if (_explicitScopePolicyMixin == null)
55                         _explicitScopePolicyMixin = new ExplicitScopeAssemblyPolicyMixin();
56                 }
57             }
58 
59             return _explicitScopePolicyMixin.GetModuleOfType(typeDef);
60         }
61     }
62 }
63