TrimmingAttributes.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma warning disable MA0048 // File name must match type name
  2. // https://github.com/dotnet/runtime/tree/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis
  3. // Licensed to the .NET Foundation under one or more agreements.
  4. // The .NET Foundation licenses this file to you under the MIT license.
  5. // See the LICENSE file in the project root for more information.
  6. namespace System.Diagnostics.CodeAnalysis
  7. {
  8. #nullable enable
  9. #if !NET6_0_OR_GREATER
  10. [AttributeUsage(
  11. AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter |
  12. AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method |
  13. AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct,
  14. Inherited = false)]
  15. internal sealed class DynamicallyAccessedMembersAttribute : Attribute
  16. {
  17. public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
  18. {
  19. MemberTypes = memberTypes;
  20. }
  21. public DynamicallyAccessedMemberTypes MemberTypes { get; }
  22. }
  23. [Flags]
  24. internal enum DynamicallyAccessedMemberTypes
  25. {
  26. None = 0,
  27. PublicParameterlessConstructor = 0x0001,
  28. PublicConstructors = 0x0002 | PublicParameterlessConstructor,
  29. NonPublicConstructors = 0x0004,
  30. PublicMethods = 0x0008,
  31. NonPublicMethods = 0x0010,
  32. PublicFields = 0x0020,
  33. NonPublicFields = 0x0040,
  34. PublicNestedTypes = 0x0080,
  35. NonPublicNestedTypes = 0x0100,
  36. PublicProperties = 0x0200,
  37. NonPublicProperties = 0x0400,
  38. PublicEvents = 0x0800,
  39. NonPublicEvents = 0x1000,
  40. Interfaces = 0x2000,
  41. All = ~None
  42. }
  43. [AttributeUsage(
  44. AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method,
  45. AllowMultiple = true, Inherited = false)]
  46. internal sealed class DynamicDependencyAttribute : Attribute
  47. {
  48. public DynamicDependencyAttribute(string memberSignature)
  49. {
  50. MemberSignature = memberSignature;
  51. }
  52. public DynamicDependencyAttribute(string memberSignature, Type type)
  53. {
  54. MemberSignature = memberSignature;
  55. Type = type;
  56. }
  57. public DynamicDependencyAttribute(string memberSignature, string typeName, string assemblyName)
  58. {
  59. MemberSignature = memberSignature;
  60. TypeName = typeName;
  61. AssemblyName = assemblyName;
  62. }
  63. public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, Type type)
  64. {
  65. MemberTypes = memberTypes;
  66. Type = type;
  67. }
  68. public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, string typeName, string assemblyName)
  69. {
  70. MemberTypes = memberTypes;
  71. TypeName = typeName;
  72. AssemblyName = assemblyName;
  73. }
  74. public string? MemberSignature { get; }
  75. public DynamicallyAccessedMemberTypes MemberTypes { get; }
  76. public Type? Type { get; }
  77. public string? TypeName { get; }
  78. public string? AssemblyName { get; }
  79. public string? Condition { get; set; }
  80. }
  81. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)]
  82. internal sealed class RequiresUnreferencedCodeAttribute : Attribute
  83. {
  84. public RequiresUnreferencedCodeAttribute(string message)
  85. {
  86. Message = message;
  87. }
  88. public string Message { get; }
  89. public string? Url { get; set; }
  90. }
  91. [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
  92. internal sealed class UnconditionalSuppressMessageAttribute : Attribute
  93. {
  94. public UnconditionalSuppressMessageAttribute(string category, string checkId)
  95. {
  96. Category = category;
  97. CheckId = checkId;
  98. }
  99. public string Category { get; }
  100. public string CheckId { get; }
  101. public string? Scope { get; set; }
  102. public string? Target { get; set; }
  103. public string? MessageId { get; set; }
  104. public string? Justification { get; set; }
  105. }
  106. #endif
  107. }