|
| 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 | + |
| 4 | +#pragma warning disable IDE0079 |
| 5 | +#pragma warning disable SA1101 |
| 6 | +#pragma warning disable SA1116 |
| 7 | +#pragma warning disable SA1117 |
| 8 | +#pragma warning disable SA1512 |
| 9 | +#pragma warning disable SA1623 |
| 10 | +#pragma warning disable SA1642 |
| 11 | +#pragma warning disable S3903 |
| 12 | + |
| 13 | +namespace System.Diagnostics.CodeAnalysis; |
| 14 | + |
| 15 | +/// <summary> |
| 16 | +/// States a dependency that one member has on another. |
| 17 | +/// </summary> |
| 18 | +/// <remarks> |
| 19 | +/// This can be used to inform tooling of a dependency that is otherwise not evident purely from |
| 20 | +/// metadata and IL, for example a member relied on via reflection. |
| 21 | +/// </remarks> |
| 22 | +[AttributeUsage( |
| 23 | + AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method, |
| 24 | + AllowMultiple = true, Inherited = false)] |
| 25 | +[ExcludeFromCodeCoverage] |
| 26 | +internal sealed class DynamicDependencyAttribute : Attribute |
| 27 | +{ |
| 28 | + /// <summary> |
| 29 | + /// Initializes a new instance of the <see cref="DynamicDependencyAttribute"/> class |
| 30 | + /// with the specified signature of a member on the same type as the consumer. |
| 31 | + /// </summary> |
| 32 | + /// <param name="memberSignature">The signature of the member depended on.</param> |
| 33 | + public DynamicDependencyAttribute(string memberSignature) => MemberSignature = memberSignature; |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Initializes a new instance of the <see cref="DynamicDependencyAttribute"/> class |
| 37 | + /// with the specified signature of a member on a <see cref="System.Type"/>. |
| 38 | + /// </summary> |
| 39 | + /// <param name="memberSignature">The signature of the member depended on.</param> |
| 40 | + /// <param name="type">The <see cref="System.Type"/> containing <paramref name="memberSignature"/>.</param> |
| 41 | + public DynamicDependencyAttribute(string memberSignature, Type type) |
| 42 | + { |
| 43 | + MemberSignature = memberSignature; |
| 44 | + Type = type; |
| 45 | + } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Initializes a new instance of the <see cref="DynamicDependencyAttribute"/> class |
| 49 | + /// with the specified signature of a member on a type in an assembly. |
| 50 | + /// </summary> |
| 51 | + /// <param name="memberSignature">The signature of the member depended on.</param> |
| 52 | + /// <param name="typeName">The full name of the type containing the specified member.</param> |
| 53 | + /// <param name="assemblyName">The assembly name of the type containing the specified member.</param> |
| 54 | + public DynamicDependencyAttribute(string memberSignature, string typeName, string assemblyName) |
| 55 | + { |
| 56 | + MemberSignature = memberSignature; |
| 57 | + TypeName = typeName; |
| 58 | + AssemblyName = assemblyName; |
| 59 | + } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Initializes a new instance of the <see cref="DynamicDependencyAttribute"/> class |
| 63 | + /// with the specified types of members on a <see cref="System.Type"/>. |
| 64 | + /// </summary> |
| 65 | + /// <param name="memberTypes">The types of members depended on.</param> |
| 66 | + /// <param name="type">The <see cref="System.Type"/> containing the specified members.</param> |
| 67 | + public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, Type type) |
| 68 | + { |
| 69 | + MemberTypes = memberTypes; |
| 70 | + Type = type; |
| 71 | + } |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// Initializes a new instance of the <see cref="DynamicDependencyAttribute"/> class |
| 75 | + /// with the specified types of members on a type in an assembly. |
| 76 | + /// </summary> |
| 77 | + /// <param name="memberTypes">The types of members depended on.</param> |
| 78 | + /// <param name="typeName">The full name of the type containing the specified members.</param> |
| 79 | + /// <param name="assemblyName">The assembly name of the type containing the specified members.</param> |
| 80 | + public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, string typeName, string assemblyName) |
| 81 | + { |
| 82 | + MemberTypes = memberTypes; |
| 83 | + TypeName = typeName; |
| 84 | + AssemblyName = assemblyName; |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Gets the signature of the member depended on. |
| 89 | + /// </summary> |
| 90 | + /// <remarks> |
| 91 | + /// Either <see cref="MemberSignature"/> must be a valid string or <see cref="MemberTypes"/> |
| 92 | + /// must not equal <see cref="DynamicallyAccessedMemberTypes.None"/>, but not both. |
| 93 | + /// </remarks> |
| 94 | + public string? MemberSignature { get; } |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// Gets the <see cref="DynamicallyAccessedMemberTypes"/> which specifies the type |
| 98 | + /// of members depended on. |
| 99 | + /// </summary> |
| 100 | + /// <remarks> |
| 101 | + /// Either <see cref="MemberSignature"/> must be a valid string or <see cref="MemberTypes"/> |
| 102 | + /// must not equal <see cref="DynamicallyAccessedMemberTypes.None"/>, but not both. |
| 103 | + /// </remarks> |
| 104 | + public DynamicallyAccessedMemberTypes MemberTypes { get; } |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Gets the <see cref="System.Type"/> containing the specified member. |
| 108 | + /// </summary> |
| 109 | + /// <remarks> |
| 110 | + /// If neither <see cref="Type"/> nor <see cref="TypeName"/> are specified, |
| 111 | + /// the type of the consumer is assumed. |
| 112 | + /// </remarks> |
| 113 | + public Type? Type { get; } |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Gets the full name of the type containing the specified member. |
| 117 | + /// </summary> |
| 118 | + /// <remarks> |
| 119 | + /// If neither <see cref="Type"/> nor <see cref="TypeName"/> are specified, |
| 120 | + /// the type of the consumer is assumed. |
| 121 | + /// </remarks> |
| 122 | + public string? TypeName { get; } |
| 123 | + |
| 124 | + /// <summary> |
| 125 | + /// Gets the assembly name of the specified type. |
| 126 | + /// </summary> |
| 127 | + /// <remarks> |
| 128 | + /// <see cref="AssemblyName"/> is only valid when <see cref="TypeName"/> is specified. |
| 129 | + /// </remarks> |
| 130 | + public string? AssemblyName { get; } |
| 131 | + |
| 132 | + /// <summary> |
| 133 | + /// Gets or sets the condition in which the dependency is applicable, e.g. "DEBUG". |
| 134 | + /// </summary> |
| 135 | + public string? Condition { get; set; } |
| 136 | +} |
0 commit comments