@@ -24,6 +24,12 @@ public static class ProtoMessageIdHandler
2424 /// <returns>请求的类型</returns>
2525 public static Type GetReqTypeById ( int messageId )
2626 {
27+ if ( ReqDictionary . Count <= 0 )
28+ {
29+ Log . Warning ( "请先确认是否初始化 调用 ProtoMessageIdHandler.Init()" ) ;
30+ return null ;
31+ }
32+
2733 ReqDictionary . TryGetValue ( messageId , out var value ) ;
2834 return value ;
2935 }
@@ -35,6 +41,12 @@ public static Type GetReqTypeById(int messageId)
3541 /// <returns>请求消息ID</returns>
3642 public static int GetReqMessageIdByType ( Type type )
3743 {
44+ if ( ReqDictionary . Count <= 0 )
45+ {
46+ Log . Warning ( "请先确认是否初始化 调用 ProtoMessageIdHandler.Init()" ) ;
47+ return 0 ;
48+ }
49+
3850 ReqDictionary . TryGetKey ( type , out var value ) ;
3951 return value ;
4052 }
@@ -46,6 +58,12 @@ public static int GetReqMessageIdByType(Type type)
4658 /// <returns>响应的类型</returns>
4759 public static Type GetRespTypeById ( int messageId )
4860 {
61+ if ( RespDictionary . Count <= 0 )
62+ {
63+ Log . Warning ( "请先确认是否初始化 调用 ProtoMessageIdHandler.Init()" ) ;
64+ return null ;
65+ }
66+
4967 RespDictionary . TryGetValue ( messageId , out var value ) ;
5068 return value ;
5169 }
@@ -57,6 +75,12 @@ public static Type GetRespTypeById(int messageId)
5775 /// <returns>响应消息ID</returns>
5876 public static int GetRespMessageIdByType ( Type type )
5977 {
78+ if ( RespDictionary . Count <= 0 )
79+ {
80+ Log . Warning ( "请先确认是否初始化 调用 ProtoMessageIdHandler.Init()" ) ;
81+ return 0 ;
82+ }
83+
6084 RespDictionary . TryGetKey ( type , out var value ) ;
6185 return value ;
6286 }
0 commit comments