Skip to content

Commit a10452e

Browse files
committed
Small fix.
1 parent f874b5a commit a10452e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Quick.Protocol/Base.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Base
1212
Name = "基础指令集",
1313
NoticeInfos = new QpNoticeInfo[]
1414
{
15-
QpNoticeInfo.Create(new Notices.PrivateNotice())
15+
QpNoticeInfo.Create<Notices.PrivateNotice>()
1616
},
1717
CommandInfos = new QpCommandInfo[]
1818
{

Quick.Protocol/QpCommandInfo.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ public QpCommandInfo(string name, string description,
8888
/// <returns></returns>
8989
public static QpCommandInfo Create<TResponse>(IQpCommandRequest<TResponse> request)
9090
where TResponse : class, new()
91+
{
92+
return Create(request, new TResponse());
93+
}
94+
95+
public static QpCommandInfo Create<TResponse>(IQpCommandRequest<TResponse> request, TResponse response)
96+
where TResponse : class, new()
9197
{
9298
var requestType = request.GetType();
9399
var responseType = typeof(TResponse);
@@ -96,7 +102,7 @@ public static QpCommandInfo Create<TResponse>(IQpCommandRequest<TResponse> reque
96102
name = requestType.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
97103
if (name == null)
98104
name = requestType.FullName;
99-
return new QpCommandInfo(name, requestType.GetCustomAttribute<DescriptionAttribute>()?.Description, requestType, responseType, request, new TResponse());
105+
return new QpCommandInfo(name, requestType.GetCustomAttribute<DescriptionAttribute>()?.Description, requestType, responseType, request, response);
100106
}
101107
}
102108
}

Quick.Protocol/QpNoticeInfo.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,22 @@ public QpNoticeInfo(string name, string description, Type noticeType, object def
5757
/// <summary>
5858
/// 创建通知信息实例
5959
/// </summary>
60-
/// <param name="instance"></param>
60+
/// <typeparam name="T"></typeparam>
61+
/// <returns></returns>
62+
public static QpNoticeInfo Create<T>()
63+
where T : new()
64+
{
65+
return Create<T>(new T());
66+
}
67+
68+
/// <summary>
69+
/// 创建通知信息实例
70+
/// </summary>
71+
/// <typeparam name="T"></typeparam>
6172
/// <returns></returns>
6273
public static QpNoticeInfo Create<T>(T instance)
6374
{
64-
var type =typeof(T);
75+
var type = typeof(T);
6576
string name = null;
6677
if (name == null)
6778
name = type.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;

0 commit comments

Comments
 (0)