• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 
3 // Copyright 2015-2016 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #endregion
18 
19 // Content of this file is copied with permission from:
20 // https://github.com/dotnet/runtime/tree/e2e43f44f1032780fa7c2bb965153c9da615c3d0/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis
21 // These types are intented to be added as internalized source to libraries and apps that want to
22 // use them without requiring a dependency on .NET 5.
23 
24 namespace System.Diagnostics.CodeAnalysis
25 {
26     /// <summary>
27     /// Indicates that certain members on a specified <see cref="Type"/> are accessed dynamically,
28     /// for example through <see cref="System.Reflection"/>.
29     /// </summary>
30     /// <remarks>
31     /// This allows tools to understand which members are being accessed during the execution
32     /// of a program.
33     ///
34     /// This attribute is valid on members whose type is <see cref="Type"/> or <see cref="string"/>.
35     ///
36     /// When this attribute is applied to a location of type <see cref="string"/>, the assumption is
37     /// that the string represents a fully qualified type name.
38     ///
39     /// If the attribute is applied to a method it's treated as a special case and it implies
40     /// the attribute should be applied to the "this" parameter of the method. As such the attribute
41     /// should only be used on instance methods of types assignable to System.Type (or string, but no methods
42     /// will use it there).
43     /// </remarks>
44     [AttributeUsage(
45         AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
46         AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method,
47         Inherited = false)]
48     internal sealed class DynamicallyAccessedMembersAttribute : Attribute
49     {
50         /// <summary>
51         /// Initializes a new instance of the <see cref="DynamicallyAccessedMembersAttribute"/> class
52         /// with the specified member types.
53         /// </summary>
54         /// <param name="memberTypes">The types of members dynamically accessed.</param>
DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)55         public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
56         {
57             MemberTypes = memberTypes;
58         }
59 
60         /// <summary>
61         /// Gets the <see cref="DynamicallyAccessedMemberTypes"/> which specifies the type
62         /// of members dynamically accessed.
63         /// </summary>
64         public DynamicallyAccessedMemberTypes MemberTypes { get; }
65     }
66 
67     /// <summary>
68     /// Specifies the types of members that are dynamically accessed.
69     ///
70     /// This enumeration has a <see cref="FlagsAttribute"/> attribute that allows a
71     /// bitwise combination of its member values.
72     /// </summary>
73     [Flags]
74     internal enum DynamicallyAccessedMemberTypes
75     {
76         /// <summary>
77         /// Specifies no members.
78         /// </summary>
79         None = 0,
80 
81         /// <summary>
82         /// Specifies the default, parameterless public constructor.
83         /// </summary>
84         PublicParameterlessConstructor = 0x0001,
85 
86         /// <summary>
87         /// Specifies all public constructors.
88         /// </summary>
89         PublicConstructors = 0x0002 | PublicParameterlessConstructor,
90 
91         /// <summary>
92         /// Specifies all non-public constructors.
93         /// </summary>
94         NonPublicConstructors = 0x0004,
95 
96         /// <summary>
97         /// Specifies all public methods.
98         /// </summary>
99         PublicMethods = 0x0008,
100 
101         /// <summary>
102         /// Specifies all non-public methods.
103         /// </summary>
104         NonPublicMethods = 0x0010,
105 
106         /// <summary>
107         /// Specifies all public fields.
108         /// </summary>
109         PublicFields = 0x0020,
110 
111         /// <summary>
112         /// Specifies all non-public fields.
113         /// </summary>
114         NonPublicFields = 0x0040,
115 
116         /// <summary>
117         /// Specifies all public nested types.
118         /// </summary>
119         PublicNestedTypes = 0x0080,
120 
121         /// <summary>
122         /// Specifies all non-public nested types.
123         /// </summary>
124         NonPublicNestedTypes = 0x0100,
125 
126         /// <summary>
127         /// Specifies all public properties.
128         /// </summary>
129         PublicProperties = 0x0200,
130 
131         /// <summary>
132         /// Specifies all non-public properties.
133         /// </summary>
134         NonPublicProperties = 0x0400,
135 
136         /// <summary>
137         /// Specifies all public events.
138         /// </summary>
139         PublicEvents = 0x0800,
140 
141         /// <summary>
142         /// Specifies all non-public events.
143         /// </summary>
144         NonPublicEvents = 0x1000,
145 
146         /// <summary>
147         /// Specifies all members.
148         /// </summary>
149         All = ~None
150     }
151 }
152