@@ -49,8 +49,7 @@ public void SendMessage(object message, IPEndPoint endPoint)
49
49
object [ ] attribute = message . GetType ( ) . GetCustomAttributes ( typeof ( MessageAttribute ) , false ) ;
50
50
if ( attribute . Length <= 0 )
51
51
throw new GT . GamekException ( "class not found MessageAttribute" ) ;
52
- MessageAttribute mgAttribute = attribute [ 0 ] as MessageAttribute ;
53
- if ( mgAttribute != null )
52
+ if ( attribute [ 0 ] is MessageAttribute mgAttribute )
54
53
GT . GameMode . Network . SendMessage ( mgAttribute . TypeCode , messageData , endPoint ) ;
55
54
}
56
55
@@ -76,23 +75,24 @@ private void LoadMessageAttribute()
76
75
object [ ] attribute = item . GetCustomAttributes ( typeof ( MessageHandlerAttribute ) , false ) ;
77
76
if ( attribute . Length > 0 && ! item . IsAbstract )
78
77
{
79
- MessageHandlerAttribute msHanderAttibute = attribute [ 0 ] as MessageHandlerAttribute ;
80
- if ( msHanderAttibute != null )
78
+ if ( attribute [ 0 ] is MessageHandlerAttribute msHanderAttibute )
81
79
{
82
80
Type handType = Type . GetType ( msHanderAttibute . TypeMessage ) ;
83
- if ( ! _messageHandler . ContainsKey ( handType ) )
84
- _messageHandler [ handType ] = new List < MessageHandlerBase > ( ) ;
85
- _messageHandler [ handType ]
86
- . Add ( ( MessageHandlerBase ) Activator . CreateInstance ( item ) ) ;
81
+ if ( handType != null )
82
+ {
83
+ if ( ! _messageHandler . ContainsKey ( handType ) )
84
+ _messageHandler [ handType ] = new List < MessageHandlerBase > ( ) ;
85
+ _messageHandler [ handType ]
86
+ . Add ( ( MessageHandlerBase ) Activator . CreateInstance ( item ) ) ;
87
+ }
87
88
}
88
89
}
89
90
90
91
//get message
91
92
attribute = item . GetCustomAttributes ( typeof ( MessageAttribute ) , false ) ;
92
93
if ( attribute . Length > 0 && ! item . IsAbstract )
93
94
{
94
- MessageAttribute msAttibute = attribute [ 0 ] as MessageAttribute ;
95
- if ( msAttibute != null )
95
+ if ( attribute [ 0 ] is MessageAttribute msAttibute )
96
96
_messageCodeType [ msAttibute . TypeCode ] = item ;
97
97
}
98
98
0 commit comments