|
| 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 | +#nullable enable |
| 6 | + |
| 7 | +// TODO https://github.com/dotnet/corefx/issues/41201: Design and expose this publicly. |
| 8 | + |
| 9 | +namespace System.Runtime.CompilerServices |
| 10 | +{ |
| 11 | + /// <summary>States a dependency that one member has on another.</summary> |
| 12 | + /// <remarks> |
| 13 | + /// This can be used to inform tooling of a dependency that is otherwise not evident purely from |
| 14 | + /// metadata and IL, for example a member relied on via reflection. |
| 15 | + /// </remarks> |
| 16 | + [AttributeUsage( |
| 17 | + AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field /* AttributeTargets.Class | AttributeTargets.Struct */, // TODO: https://github.com/mono/linker/issues/797 |
| 18 | + AllowMultiple = true, Inherited = false)] |
| 19 | + internal sealed class PreserveDependencyAttribute : Attribute |
| 20 | + { |
| 21 | + /// <summary>Initializes the attribute.</summary> |
| 22 | + /// <param name="memberSignature">The signature of the member depended.</param> |
| 23 | + public PreserveDependencyAttribute(string memberSignature) |
| 24 | + { |
| 25 | + MemberSignature = memberSignature; |
| 26 | + } |
| 27 | + |
| 28 | + /// <summary>Initializes the attribute.</summary> |
| 29 | + /// <param name="memberSignature">The signature of the member depended on.</param> |
| 30 | + /// <param name="typeName">The full name of the type containing <paramref name="memberSignature"/>.</param> |
| 31 | + public PreserveDependencyAttribute(string memberSignature, string typeName) |
| 32 | + { |
| 33 | + MemberSignature = memberSignature; |
| 34 | + TypeName = typeName; |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary>Initializes the attribute.</summary> |
| 38 | + /// <param name="memberSignature">The signature of the member depended on.</param> |
| 39 | + /// <param name="typeName">The full name of the type containing <paramref name="memberSignature"/>.</param> |
| 40 | + /// <param name="assemblyName">The name of the assembly containing <paramref name="typeName"/>.</param> |
| 41 | + public PreserveDependencyAttribute(string memberSignature, string typeName, string assemblyName) |
| 42 | + { |
| 43 | + MemberSignature = memberSignature; |
| 44 | + TypeName = typeName; |
| 45 | + AssemblyName = assemblyName; |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary>Gets the signature of the member depended on.</summary> |
| 49 | + public string MemberSignature { get; } |
| 50 | + |
| 51 | + /// <summary>Gets the full name of the type containing the specified member.</summary> |
| 52 | + /// <remarks>If no type name is specified, the type of the consumer is assumed.</remarks> |
| 53 | + public string? TypeName { get; } |
| 54 | + |
| 55 | + /// <summary>Gets the assembly name of the specified type.</summary> |
| 56 | + /// <remarks>If no assembly name is specified, the assembly of the consumer is assumed.</remarks> |
| 57 | + public string? AssemblyName { get; } |
| 58 | + |
| 59 | + /// <summary>Gets or sets the condition in which the dependency is applicable, e.g. "DEBUG".</summary> |
| 60 | + public string? Condition { get; set; } |
| 61 | + } |
| 62 | +} |
0 commit comments