Skip to content

Commit 76d13af

Browse files
committed
style: global-using format code
1 parent 61a7ece commit 76d13af

File tree

170 files changed

+8162
-8560
lines changed

Some content is hidden

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

170 files changed

+8162
-8560
lines changed
Lines changed: 115 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,123 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Runtime.Serialization;
1+
using System.Runtime.Serialization;
42
using Bing.Exceptions;
53

6-
namespace Bing
4+
namespace Bing;
5+
6+
/// <summary>
7+
/// Bing异常
8+
/// </summary>
9+
[Serializable]
10+
public abstract class BingException : Exception
711
{
812
/// <summary>
9-
/// Bing异常
13+
/// 空标识
14+
/// </summary>
15+
protected const string EmptyFlag = "__EMPTY_FLG";
16+
17+
/// <summary>
18+
/// 默认错误消息
19+
/// </summary>
20+
protected const string DefaultErrorMessage = "_DEFAULT_ERROR";
21+
22+
/// <summary>
23+
/// 默认错误编码
24+
/// </summary>
25+
protected const long DefaultErrorCode = 1001;
26+
27+
/// <summary>
28+
/// 默认扩展错误编码
29+
/// </summary>
30+
protected const long DefaultExtendErrorCode = 1002;
31+
32+
/// <summary>
33+
/// 初始化一个<see cref="BingException"/>类型的实例
34+
/// </summary>
35+
protected BingException() : this(DefaultErrorCode, DefaultErrorMessage, EmptyFlag) { }
36+
37+
/// <summary>
38+
/// 初始化一个<see cref="BingException"/>类型的实例
39+
/// </summary>
40+
/// <param name="errorMessage">错误消息</param>
41+
/// <param name="innerException">内部异常</param>
42+
protected BingException(string errorMessage, Exception innerException = null) : this(errorMessage, EmptyFlag, innerException) { }
43+
44+
/// <summary>
45+
/// 初始化一个<see cref="BingException"/>类型的实例
46+
/// </summary>
47+
/// <param name="errorMessage">错误消息</param>
48+
/// <param name="flag">错误标识</param>
49+
/// <param name="innerException">内部异常</param>
50+
protected BingException(string errorMessage, string flag, Exception innerException = null) : this(DefaultExtendErrorCode, errorMessage, flag, innerException) { }
51+
52+
/// <summary>
53+
/// 初始化一个<see cref="BingException"/>类型的实例
54+
/// </summary>
55+
/// <param name="errorCode">错误码</param>
56+
/// <param name="errorMessage">错误消息</param>
57+
/// <param name="innerException">内部异常</param>
58+
protected BingException(long errorCode, string errorMessage, Exception innerException = null) : this(errorCode, errorMessage, EmptyFlag, innerException) { }
59+
60+
/// <summary>
61+
/// 初始化一个<see cref="BingException"/>类型的实例
1062
/// </summary>
11-
[Serializable]
12-
public abstract class BingException : Exception
63+
/// <param name="info">序列化信息</param>
64+
/// <param name="context">流上下文</param>
65+
protected BingException(SerializationInfo info, StreamingContext context) : base(info, context)
1366
{
14-
/// <summary>
15-
/// 空标识
16-
/// </summary>
17-
protected const string EmptyFlag = "__EMPTY_FLG";
18-
19-
/// <summary>
20-
/// 默认错误消息
21-
/// </summary>
22-
protected const string DefaultErrorMessage = "_DEFAULT_ERROR";
23-
24-
/// <summary>
25-
/// 默认错误编码
26-
/// </summary>
27-
protected const long DefaultErrorCode = 1001;
28-
29-
/// <summary>
30-
/// 默认扩展错误编码
31-
/// </summary>
32-
protected const long DefaultExtendErrorCode = 1002;
33-
34-
/// <summary>
35-
/// 初始化一个<see cref="BingException"/>类型的实例
36-
/// </summary>
37-
protected BingException() : this(DefaultErrorCode, DefaultErrorMessage, EmptyFlag) { }
38-
39-
/// <summary>
40-
/// 初始化一个<see cref="BingException"/>类型的实例
41-
/// </summary>
42-
/// <param name="errorMessage">错误消息</param>
43-
/// <param name="innerException">内部异常</param>
44-
protected BingException(string errorMessage, Exception innerException = null) : this(errorMessage, EmptyFlag, innerException) { }
45-
46-
/// <summary>
47-
/// 初始化一个<see cref="BingException"/>类型的实例
48-
/// </summary>
49-
/// <param name="errorMessage">错误消息</param>
50-
/// <param name="flag">错误标识</param>
51-
/// <param name="innerException">内部异常</param>
52-
protected BingException(string errorMessage, string flag, Exception innerException = null) : this(DefaultExtendErrorCode, errorMessage, flag, innerException) { }
53-
54-
/// <summary>
55-
/// 初始化一个<see cref="BingException"/>类型的实例
56-
/// </summary>
57-
/// <param name="errorCode">错误码</param>
58-
/// <param name="errorMessage">错误消息</param>
59-
/// <param name="innerException">内部异常</param>
60-
protected BingException(long errorCode, string errorMessage, Exception innerException = null) : this(errorCode, errorMessage, EmptyFlag, innerException) { }
61-
62-
/// <summary>
63-
/// 初始化一个<see cref="BingException"/>类型的实例
64-
/// </summary>
65-
/// <param name="info">序列化信息</param>
66-
/// <param name="context">流上下文</param>
67-
protected BingException(SerializationInfo info, StreamingContext context) : base(info, context)
68-
{
69-
ExtraData = new Dictionary<string, object>();
70-
Code = DefaultExtendErrorCode;
71-
Flag = EmptyFlag;
72-
}
73-
74-
/// <summary>
75-
/// 初始化一个<see cref="BingException"/>类型的实例
76-
/// </summary>
77-
/// <param name="errorCode">错误码</param>
78-
/// <param name="errorMessage">错误消息</param>
79-
/// <param name="flag">错误标识</param>
80-
/// <param name="innerException">内部异常</param>
81-
protected BingException(long errorCode, string errorMessage, string flag, Exception innerException = null) : base(errorMessage, innerException)
82-
{
83-
if (string.IsNullOrWhiteSpace(flag))
84-
flag = EmptyFlag;
85-
ExtraData = new Dictionary<string, object>();
86-
Code = errorCode;
87-
Flag = flag;
88-
}
89-
90-
/// <summary>
91-
/// 初始化一个<see cref="BingException"/>类型的实例
92-
/// </summary>
93-
/// <param name="options">Bing框架异常选项配置</param>
94-
protected BingException(BingExceptionOptions options) : base(options.Message, options.InnerException)
95-
{
96-
ExtraData = options.ExtraErrors;
97-
Code = options.ErrorCode;
98-
Flag = options.Flag;
99-
}
100-
101-
/// <summary>
102-
/// 错误码
103-
/// </summary>
104-
public long Code { get; protected set; }
105-
106-
/// <summary>
107-
/// 错误标识
108-
/// </summary>
109-
public string Flag { get; protected set; }
110-
111-
/// <summary>
112-
/// 额外数据
113-
/// </summary>
114-
public Dictionary<string, object> ExtraData { get; }
115-
116-
/// <summary>
117-
/// 获取完整的消息
118-
/// </summary>
119-
public virtual string GetFullMessage() => $"{Code}:({Flag}){Message}";
120-
121-
/// <summary>
122-
/// 抛出异常
123-
/// </summary>
124-
public virtual void Throw() => ExceptionHelper.PrepareForRethrow(this);
67+
ExtraData = new Dictionary<string, object>();
68+
Code = DefaultExtendErrorCode;
69+
Flag = EmptyFlag;
12570
}
71+
72+
/// <summary>
73+
/// 初始化一个<see cref="BingException"/>类型的实例
74+
/// </summary>
75+
/// <param name="errorCode">错误码</param>
76+
/// <param name="errorMessage">错误消息</param>
77+
/// <param name="flag">错误标识</param>
78+
/// <param name="innerException">内部异常</param>
79+
protected BingException(long errorCode, string errorMessage, string flag, Exception innerException = null) : base(errorMessage, innerException)
80+
{
81+
if (string.IsNullOrWhiteSpace(flag))
82+
flag = EmptyFlag;
83+
ExtraData = new Dictionary<string, object>();
84+
Code = errorCode;
85+
Flag = flag;
86+
}
87+
88+
/// <summary>
89+
/// 初始化一个<see cref="BingException"/>类型的实例
90+
/// </summary>
91+
/// <param name="options">Bing框架异常选项配置</param>
92+
protected BingException(BingExceptionOptions options) : base(options.Message, options.InnerException)
93+
{
94+
ExtraData = options.ExtraErrors;
95+
Code = options.ErrorCode;
96+
Flag = options.Flag;
97+
}
98+
99+
/// <summary>
100+
/// 错误码
101+
/// </summary>
102+
public long Code { get; protected set; }
103+
104+
/// <summary>
105+
/// 错误标识
106+
/// </summary>
107+
public string Flag { get; protected set; }
108+
109+
/// <summary>
110+
/// 额外数据
111+
/// </summary>
112+
public Dictionary<string, object> ExtraData { get; }
113+
114+
/// <summary>
115+
/// 获取完整的消息
116+
/// </summary>
117+
public virtual string GetFullMessage() => $"{Code}:({Flag}){Message}";
118+
119+
/// <summary>
120+
/// 抛出异常
121+
/// </summary>
122+
public virtual void Throw() => ExceptionHelper.PrepareForRethrow(this);
126123
}
Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
1-
using System;
1+
namespace Bing;
22

3-
namespace Bing
3+
/// <summary>
4+
/// Bing框架异常
5+
/// </summary>
6+
public class BingFrameworkException : BingException
47
{
58
/// <summary>
6-
/// Bing框架异常
9+
/// 框架标识
710
/// </summary>
8-
public class BingFrameworkException : BingException
9-
{
10-
/// <summary>
11-
/// 框架标识
12-
/// </summary>
13-
private const string BingFrameworkFlag = "BING_FRM_FLG";
11+
private const string BingFrameworkFlag = "BING_FRM_FLG";
1412

15-
/// <summary>
16-
/// 框架内部消息
17-
/// </summary>
18-
private const string FrameworkInnerMessage = "Bing框架内部异常";
13+
/// <summary>
14+
/// 框架内部消息
15+
/// </summary>
16+
private const string FrameworkInnerMessage = "Bing框架内部异常";
1917

20-
/// <summary>
21-
/// 初始化一个<see cref="BingFrameworkException"/>类型的实例
22-
/// </summary>
23-
public BingFrameworkException() : this(FrameworkInnerMessage) { }
18+
/// <summary>
19+
/// 初始化一个<see cref="BingFrameworkException"/>类型的实例
20+
/// </summary>
21+
public BingFrameworkException() : this(FrameworkInnerMessage) { }
2422

25-
/// <summary>
26-
/// 初始化一个<see cref="BingFrameworkException"/>类型的实例
27-
/// </summary>
28-
/// <param name="errorMessage">错误消息</param>
29-
public BingFrameworkException(string errorMessage) : this(DefaultErrorCode, errorMessage)
30-
{
31-
}
23+
/// <summary>
24+
/// 初始化一个<see cref="BingFrameworkException"/>类型的实例
25+
/// </summary>
26+
/// <param name="errorMessage">错误消息</param>
27+
public BingFrameworkException(string errorMessage) : this(DefaultErrorCode, errorMessage)
28+
{
29+
}
3230

33-
/// <summary>
34-
/// 初始化一个<see cref="BingFrameworkException"/>类型的实例
35-
/// </summary>
36-
/// <param name="errorCode">错误码</param>
37-
/// <param name="errorMessage">错误消息</param>
38-
/// <param name="innerException">内部异常</param>
39-
public BingFrameworkException(long errorCode, string errorMessage, Exception innerException = null) : base(errorCode, errorMessage, BingFrameworkFlag, innerException)
40-
{
41-
}
31+
/// <summary>
32+
/// 初始化一个<see cref="BingFrameworkException"/>类型的实例
33+
/// </summary>
34+
/// <param name="errorCode">错误码</param>
35+
/// <param name="errorMessage">错误消息</param>
36+
/// <param name="innerException">内部异常</param>
37+
public BingFrameworkException(long errorCode, string errorMessage, Exception innerException = null) : base(errorCode, errorMessage, BingFrameworkFlag, innerException)
38+
{
4239
}
4340
}
Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
using System;
2-
using System.Diagnostics;
1+
using System.Diagnostics;
32
using Microsoft.Extensions.DependencyInjection;
43

5-
namespace Bing
4+
namespace Bing;
5+
6+
/// <summary>
7+
/// Bing 框架加载器
8+
/// </summary>
9+
public static class BingLoader
610
{
711
/// <summary>
8-
/// Bing 框架加载器
12+
/// 注册类型
913
/// </summary>
10-
public static class BingLoader
11-
{
12-
/// <summary>
13-
/// 注册类型
14-
/// </summary>
15-
public static event Action<Type> RegisterType;
14+
public static event Action<Type> RegisterType;
1615

17-
/// <summary>
18-
/// 注册类型
19-
/// </summary>
20-
/// <param name="services">服务集合</param>
21-
public static void RegisterTypes(IServiceCollection services)
16+
/// <summary>
17+
/// 注册类型
18+
/// </summary>
19+
/// <param name="services">服务集合</param>
20+
public static void RegisterTypes(IServiceCollection services)
21+
{
22+
if (RegisterType == null)
23+
return;
24+
var allAssemblyFinder = services.GetOrAddAllAssemblyFinder();
25+
var assemblies = allAssemblyFinder.FindAll(true);
26+
foreach (var assembly in assemblies)
2227
{
23-
if (RegisterType == null)
24-
return;
25-
var allAssemblyFinder = services.GetOrAddAllAssemblyFinder();
26-
var assemblies = allAssemblyFinder.FindAll(true);
27-
foreach (var assembly in assemblies)
28-
{
29-
var types = assembly.GetTypes();
30-
Debug.WriteLine($"Assembly: {assembly.FullName}, TypeLength: {types.Length}");
31-
foreach (var type in types)
32-
RegisterType(type);
33-
}
28+
var types = assembly.GetTypes();
29+
Debug.WriteLine($"Assembly: {assembly.FullName}, TypeLength: {types.Length}");
30+
foreach (var type in types)
31+
RegisterType(type);
3432
}
3533
}
3634
}

0 commit comments

Comments
 (0)