• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2015 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 #if !NET5_0_OR_GREATER
11 // Copied with permission from https://github.com/dotnet/runtime/tree/8fbf206d0e518b45ca855832e8bfb391afa85972/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis
12 namespace System.Diagnostics.CodeAnalysis
13 {
14     /// <summary>
15     /// Indicates that certain members on a specified <see cref="Type"/> are accessed dynamically,
16     /// for example through <see cref="System.Reflection"/>.
17     /// </summary>
18     /// <remarks>
19     /// This allows tools to understand which members are being accessed during the execution
20     /// of a program.
21     ///
22     /// This attribute is valid on members whose type is <see cref="Type"/> or <see cref="string"/>.
23     ///
24     /// When this attribute is applied to a location of type <see cref="string"/>, the assumption is
25     /// that the string represents a fully qualified type name.
26     ///
27     /// When this attribute is applied to a class, interface, or struct, the members specified
28     /// can be accessed dynamically on <see cref="Type"/> instances returned from calling
29     /// <see cref="object.GetType"/> on instances of that class, interface, or struct.
30     ///
31     /// If the attribute is applied to a method it's treated as a special case and it implies
32     /// the attribute should be applied to the "this" parameter of the method. As such the attribute
33     /// should only be used on instance methods of types assignable to System.Type (or string, but no methods
34     /// will use it there).
35     /// </remarks>
36     [AttributeUsage(
37         AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
38         AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method |
39         AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct,
40         Inherited = false)]
41     internal sealed class DynamicallyAccessedMembersAttribute : Attribute
42     {
43         /// <summary>
44         /// Initializes a new instance of the <see cref="DynamicallyAccessedMembersAttribute"/> class
45         /// with the specified member types.
46         /// </summary>
47         /// <param name="memberTypes">The types of members dynamically accessed.</param>
DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)48         public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
49         {
50             MemberTypes = memberTypes;
51         }
52 
53         /// <summary>
54         /// Gets the <see cref="DynamicallyAccessedMemberTypes"/> which specifies the type
55         /// of members dynamically accessed.
56         /// </summary>
57         public DynamicallyAccessedMemberTypes MemberTypes { get; }
58     }
59 }
60 #endif
61