Skip to content

Commit fa9e933

Browse files
committed
去掉条件编译指令
1 parent ac112e0 commit fa9e933

File tree

58 files changed

+753
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+753
-333
lines changed

WebApiClientCore.Abstractions/ApiActionDescriptor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ public abstract class ApiActionDescriptor
1414
/// <summary>
1515
/// 获取所在接口类型
1616
/// 这个值不一定是声明方法的接口类型
17-
/// </summary>
18-
#if NET5_0_OR_GREATER
17+
/// </summary>
1918
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
20-
#endif
2119
public abstract Type InterfaceType { get; protected set; }
2220

2321
/// <summary>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#if NETSTANDARD2_1
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// 表示动态依赖属性
6+
/// </summary>
7+
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
8+
sealed class DynamicDependencyAttribute : Attribute
9+
{
10+
/// <summary>
11+
/// 获取或设置动态访问的成员类型
12+
/// </summary>
13+
public DynamicallyAccessedMemberTypes MemberTypes { get; }
14+
15+
/// <summary>
16+
/// 获取或设置依赖的类型
17+
/// </summary>
18+
public Type? Type { get; }
19+
20+
/// <summary>
21+
/// 初始化 <see cref="DynamicDependencyAttribute"/> 类的新实例
22+
/// </summary>
23+
/// <param name="memberTypes">动态访问的成员类型</param>
24+
/// <param name="type">依赖的类型</param>
25+
public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, Type type)
26+
{
27+
this.MemberTypes = memberTypes;
28+
this.Type = type;
29+
}
30+
}
31+
}
32+
#endif
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#if NETSTANDARD2_1
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// Specifies the types of dynamically accessed members.
6+
/// </summary>
7+
enum DynamicallyAccessedMemberTypes
8+
{
9+
/// <summary>
10+
/// All member types are dynamically accessed.
11+
/// </summary>
12+
All = -1,
13+
14+
/// <summary>
15+
/// No member types are dynamically accessed.
16+
/// </summary>
17+
None = 0,
18+
19+
/// <summary>
20+
/// Public parameterless constructors are dynamically accessed.
21+
/// </summary>
22+
PublicParameterlessConstructor = 1,
23+
24+
/// <summary>
25+
/// Public constructors are dynamically accessed.
26+
/// </summary>
27+
PublicConstructors = 3,
28+
29+
/// <summary>
30+
/// Non-public constructors are dynamically accessed.
31+
/// </summary>
32+
NonPublicConstructors = 4,
33+
34+
/// <summary>
35+
/// Public methods are dynamically accessed.
36+
/// </summary>
37+
PublicMethods = 8,
38+
39+
/// <summary>
40+
/// Non-public methods are dynamically accessed.
41+
/// </summary>
42+
NonPublicMethods = 16,
43+
44+
/// <summary>
45+
/// Public fields are dynamically accessed.
46+
/// </summary>
47+
PublicFields = 32,
48+
49+
/// <summary>
50+
/// Non-public fields are dynamically accessed.
51+
/// </summary>
52+
NonPublicFields = 64,
53+
54+
/// <summary>
55+
/// Public nested types are dynamically accessed.
56+
/// </summary>
57+
PublicNestedTypes = 128,
58+
59+
/// <summary>
60+
/// Non-public nested types are dynamically accessed.
61+
/// </summary>
62+
NonPublicNestedTypes = 256,
63+
64+
/// <summary>
65+
/// Public properties are dynamically accessed.
66+
/// </summary>
67+
PublicProperties = 512,
68+
69+
/// <summary>
70+
/// Non-public properties are dynamically accessed.
71+
/// </summary>
72+
NonPublicProperties = 1024,
73+
74+
/// <summary>
75+
/// Public events are dynamically accessed.
76+
/// </summary>
77+
PublicEvents = 2048,
78+
79+
/// <summary>
80+
/// Non-public events are dynamically accessed.
81+
/// </summary>
82+
NonPublicEvents = 4096,
83+
}
84+
}
85+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#if NETSTANDARD2_1
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// Specifies that the members accessed dynamically at runtime are considered used.
6+
/// </summary>
7+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)]
8+
sealed class DynamicallyAccessedMembersAttribute : Attribute
9+
{
10+
/// <summary>
11+
/// Gets the types of dynamically accessed members.
12+
/// </summary>
13+
public DynamicallyAccessedMemberTypes MemberTypes { get; }
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="DynamicallyAccessedMembersAttribute"/> class with the specified member types.
17+
/// </summary>
18+
/// <param name="memberTypes">The types of dynamically accessed members.</param>
19+
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
20+
{
21+
this.MemberTypes = memberTypes;
22+
}
23+
}
24+
}
25+
#endif
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#if NETSTANDARD2_1
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// 表示一个用于取消对代码分析器规则的警告的特性
6+
/// </summary>
7+
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
8+
sealed class UnconditionalSuppressMessageAttribute : Attribute
9+
{
10+
/// <summary>
11+
/// 获取或设置警告的类别
12+
/// </summary>
13+
public string Category { get; }
14+
15+
/// <summary>
16+
/// 获取或设置要取消的检查标识符
17+
/// </summary>
18+
public string CheckId { get; }
19+
20+
/// <summary>
21+
/// 获取或设置取消警告的理由
22+
/// </summary>
23+
public string? Justification { get; set; }
24+
25+
/// <summary>
26+
/// 获取或设置消息的标识符
27+
/// </summary>
28+
public string? MessageId { get; set; }
29+
30+
/// <summary>
31+
/// 获取或设置取消警告的范围
32+
/// </summary>
33+
public string? Scope { get; set; }
34+
35+
/// <summary>
36+
/// 获取或设置取消警告的目标
37+
/// </summary>
38+
public string? Target { get; set; }
39+
40+
/// <summary>
41+
/// 初始化 <see cref="UnconditionalSuppressMessageAttribute"/> 类的新实例
42+
/// </summary>
43+
/// <param name="category">警告的类别</param>
44+
/// <param name="checkId">要取消的检查标识符</param>
45+
public UnconditionalSuppressMessageAttribute(string category, string checkId)
46+
{
47+
this.Category = category;
48+
this.CheckId = checkId;
49+
}
50+
}
51+
}
52+
#endif

WebApiClientCore.Abstractions/IApiActionDescriptorProvider.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ public interface IApiActionDescriptorProvider
1414
/// </summary>
1515
/// <param name="method">接口的方法</param>
1616
/// <param name="interfaceType">接口类型</param>
17-
ApiActionDescriptor CreateActionDescriptor(MethodInfo method,
18-
#if NET5_0_OR_GREATER
19-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
20-
#endif
21-
Type interfaceType);
17+
ApiActionDescriptor CreateActionDescriptor(
18+
MethodInfo method,
19+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type interfaceType);
2220
}
2321
}

WebApiClientCore.Abstractions/IHttpApiActivator.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ namespace WebApiClientCore
66
/// 定义THttpApi的实例创建器的接口
77
/// </summary>
88
/// <typeparam name="THttpApi"></typeparam>
9-
public interface IHttpApiActivator<
10-
#if NET5_0_OR_GREATER
11-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
12-
#endif
13-
THttpApi>
9+
public interface IHttpApiActivator<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] THttpApi>
1410
{
1511
/// <summary>
1612
/// 创建THttpApi的代理实例
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#if NETSTANDARD2_1
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// 表示动态依赖属性
6+
/// </summary>
7+
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
8+
sealed class DynamicDependencyAttribute : Attribute
9+
{
10+
/// <summary>
11+
/// 获取或设置动态访问的成员类型
12+
/// </summary>
13+
public DynamicallyAccessedMemberTypes MemberTypes { get; }
14+
15+
/// <summary>
16+
/// 获取或设置依赖的类型
17+
/// </summary>
18+
public Type? Type { get; }
19+
20+
/// <summary>
21+
/// 初始化 <see cref="DynamicDependencyAttribute"/> 类的新实例
22+
/// </summary>
23+
/// <param name="memberTypes">动态访问的成员类型</param>
24+
/// <param name="type">依赖的类型</param>
25+
public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, Type type)
26+
{
27+
this.MemberTypes = memberTypes;
28+
this.Type = type;
29+
}
30+
}
31+
}
32+
#endif
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#if NETSTANDARD2_1
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// Specifies the types of dynamically accessed members.
6+
/// </summary>
7+
enum DynamicallyAccessedMemberTypes
8+
{
9+
/// <summary>
10+
/// All member types are dynamically accessed.
11+
/// </summary>
12+
All = -1,
13+
14+
/// <summary>
15+
/// No member types are dynamically accessed.
16+
/// </summary>
17+
None = 0,
18+
19+
/// <summary>
20+
/// Public parameterless constructors are dynamically accessed.
21+
/// </summary>
22+
PublicParameterlessConstructor = 1,
23+
24+
/// <summary>
25+
/// Public constructors are dynamically accessed.
26+
/// </summary>
27+
PublicConstructors = 3,
28+
29+
/// <summary>
30+
/// Non-public constructors are dynamically accessed.
31+
/// </summary>
32+
NonPublicConstructors = 4,
33+
34+
/// <summary>
35+
/// Public methods are dynamically accessed.
36+
/// </summary>
37+
PublicMethods = 8,
38+
39+
/// <summary>
40+
/// Non-public methods are dynamically accessed.
41+
/// </summary>
42+
NonPublicMethods = 16,
43+
44+
/// <summary>
45+
/// Public fields are dynamically accessed.
46+
/// </summary>
47+
PublicFields = 32,
48+
49+
/// <summary>
50+
/// Non-public fields are dynamically accessed.
51+
/// </summary>
52+
NonPublicFields = 64,
53+
54+
/// <summary>
55+
/// Public nested types are dynamically accessed.
56+
/// </summary>
57+
PublicNestedTypes = 128,
58+
59+
/// <summary>
60+
/// Non-public nested types are dynamically accessed.
61+
/// </summary>
62+
NonPublicNestedTypes = 256,
63+
64+
/// <summary>
65+
/// Public properties are dynamically accessed.
66+
/// </summary>
67+
PublicProperties = 512,
68+
69+
/// <summary>
70+
/// Non-public properties are dynamically accessed.
71+
/// </summary>
72+
NonPublicProperties = 1024,
73+
74+
/// <summary>
75+
/// Public events are dynamically accessed.
76+
/// </summary>
77+
PublicEvents = 2048,
78+
79+
/// <summary>
80+
/// Non-public events are dynamically accessed.
81+
/// </summary>
82+
NonPublicEvents = 4096,
83+
}
84+
}
85+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#if NETSTANDARD2_1
2+
namespace System.Diagnostics.CodeAnalysis
3+
{
4+
/// <summary>
5+
/// Specifies that the members accessed dynamically at runtime are considered used.
6+
/// </summary>
7+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)]
8+
sealed class DynamicallyAccessedMembersAttribute : Attribute
9+
{
10+
/// <summary>
11+
/// Gets the types of dynamically accessed members.
12+
/// </summary>
13+
public DynamicallyAccessedMemberTypes MemberTypes { get; }
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="DynamicallyAccessedMembersAttribute"/> class with the specified member types.
17+
/// </summary>
18+
/// <param name="memberTypes">The types of dynamically accessed members.</param>
19+
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
20+
{
21+
this.MemberTypes = memberTypes;
22+
}
23+
}
24+
}
25+
#endif

0 commit comments

Comments
 (0)