1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2015 Google Inc.  All rights reserved.
4 // https://developers.google.com/protocol-buffers/
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 //     * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #endregion
32 
33 #if !NET5_0_OR_GREATER
34 // Copied with permission from https://github.com/dotnet/runtime/tree/8fbf206d0e518b45ca855832e8bfb391afa85972/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis
35 namespace System.Diagnostics.CodeAnalysis
36 {
37     /// <summary>
38     /// Indicates that certain members on a specified <see cref="Type"/> are accessed dynamically,
39     /// for example through <see cref="System.Reflection"/>.
40     /// </summary>
41     /// <remarks>
42     /// This allows tools to understand which members are being accessed during the execution
43     /// of a program.
44     ///
45     /// This attribute is valid on members whose type is <see cref="Type"/> or <see cref="string"/>.
46     ///
47     /// When this attribute is applied to a location of type <see cref="string"/>, the assumption is
48     /// that the string represents a fully qualified type name.
49     ///
50     /// When this attribute is applied to a class, interface, or struct, the members specified
51     /// can be accessed dynamically on <see cref="Type"/> instances returned from calling
52     /// <see cref="object.GetType"/> on instances of that class, interface, or struct.
53     ///
54     /// If the attribute is applied to a method it's treated as a special case and it implies
55     /// the attribute should be applied to the "this" parameter of the method. As such the attribute
56     /// should only be used on instance methods of types assignable to System.Type (or string, but no methods
57     /// will use it there).
58     /// </remarks>
59     [AttributeUsage(
60         AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
61         AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method |
62         AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct,
63         Inherited = false)]
64     internal sealed class DynamicallyAccessedMembersAttribute : Attribute
65     {
66         /// <summary>
67         /// Initializes a new instance of the <see cref="DynamicallyAccessedMembersAttribute"/> class
68         /// with the specified member types.
69         /// </summary>
70         /// <param name="memberTypes">The types of members dynamically accessed.</param>
DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)71         public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
72         {
73             MemberTypes = memberTypes;
74         }
75 
76         /// <summary>
77         /// Gets the <see cref="DynamicallyAccessedMemberTypes"/> which specifies the type
78         /// of members dynamically accessed.
79         /// </summary>
80         public DynamicallyAccessedMemberTypes MemberTypes { get; }
81     }
82 }
83 #endif
84