@@ -77,19 +77,21 @@ internal void InitializeState()
7777 this . IgnoredEvents = new HashSet < Type > ( ) ;
7878 this . DeferredEvents = new HashSet < Type > ( ) ;
7979
80- var entryAttribute = this . GetType ( ) . GetCustomAttribute ( typeof ( OnEntryAttribute ) , true ) as OnEntryAttribute ;
81- var exitAttribute = this . GetType ( ) . GetCustomAttribute ( typeof ( OnExitAttribute ) , true ) as OnExitAttribute ;
82-
83- if ( entryAttribute != null )
80+ if ( this . GetType ( ) . GetCustomAttribute ( typeof ( OnEntryAttribute ) , true ) is OnEntryAttribute entryAttribute )
8481 {
8582 this . EntryAction = entryAttribute . Action ;
8683 }
8784
88- if ( exitAttribute != null )
85+ if ( this . GetType ( ) . GetCustomAttribute ( typeof ( OnExitAttribute ) , true ) is OnExitAttribute exitAttribute )
8986 {
9087 this . ExitAction = exitAttribute . Action ;
9188 }
9289
90+ if ( this . GetType ( ) . IsDefined ( typeof ( StartAttribute ) , false ) )
91+ {
92+ this . IsStart = true ;
93+ }
94+
9395 // Events with already declared handlers.
9496 var handledEvents = new HashSet < Type > ( ) ;
9597
@@ -99,11 +101,6 @@ internal void InitializeState()
99101 this . InstallActionHandlers ( handledEvents ) ;
100102 this . InstallIgnoreHandlers ( handledEvents ) ;
101103 this . InstallDeferHandlers ( handledEvents ) ;
102-
103- if ( this . GetType ( ) . IsDefined ( typeof ( StartAttribute ) , false ) )
104- {
105- this . IsStart = true ;
106- }
107104 }
108105
109106 /// <summary>
@@ -289,9 +286,7 @@ private void InheritActionHandlers(Type baseState, HashSet<Type> handledEvents)
289286 /// </summary>
290287 private void InstallIgnoreHandlers ( HashSet < Type > handledEvents )
291288 {
292- var ignoreEventsAttribute = this . GetType ( ) . GetCustomAttribute ( typeof ( IgnoreEventsAttribute ) , false ) as IgnoreEventsAttribute ;
293-
294- if ( ignoreEventsAttribute != null )
289+ if ( this . GetType ( ) . GetCustomAttribute ( typeof ( IgnoreEventsAttribute ) , false ) is IgnoreEventsAttribute ignoreEventsAttribute )
295290 {
296291 foreach ( var e in ignoreEventsAttribute . Events )
297292 {
@@ -315,9 +310,7 @@ private void InheritIgnoreHandlers(Type baseState, HashSet<Type> handledEvents)
315310 return ;
316311 }
317312
318- var ignoreEventsAttribute = baseState . GetCustomAttribute ( typeof ( IgnoreEventsAttribute ) , false ) as IgnoreEventsAttribute ;
319-
320- if ( ignoreEventsAttribute != null )
313+ if ( baseState . GetCustomAttribute ( typeof ( IgnoreEventsAttribute ) , false ) is IgnoreEventsAttribute ignoreEventsAttribute )
321314 {
322315 foreach ( var e in ignoreEventsAttribute . Events )
323316 {
@@ -341,8 +334,7 @@ private void InheritIgnoreHandlers(Type baseState, HashSet<Type> handledEvents)
341334 /// </summary>
342335 private void InstallDeferHandlers ( HashSet < Type > handledEvents )
343336 {
344- var deferEventsAttribute = this . GetType ( ) . GetCustomAttribute ( typeof ( DeferEventsAttribute ) , false ) as DeferEventsAttribute ;
345- if ( deferEventsAttribute != null )
337+ if ( this . GetType ( ) . GetCustomAttribute ( typeof ( DeferEventsAttribute ) , false ) is DeferEventsAttribute deferEventsAttribute )
346338 {
347339 foreach ( var e in deferEventsAttribute . Events )
348340 {
@@ -366,8 +358,7 @@ private void InheritDeferHandlers(Type baseState, HashSet<Type> handledEvents)
366358 return ;
367359 }
368360
369- var deferEventsAttribute = baseState . GetCustomAttribute ( typeof ( DeferEventsAttribute ) , false ) as DeferEventsAttribute ;
370- if ( deferEventsAttribute != null )
361+ if ( baseState . GetCustomAttribute ( typeof ( DeferEventsAttribute ) , false ) is DeferEventsAttribute deferEventsAttribute )
371362 {
372363 foreach ( var e in deferEventsAttribute . Events )
373364 {
@@ -393,7 +384,7 @@ private static void CheckEventHandlerAlreadyDeclared(Type e, HashSet<Type> handl
393384 {
394385 if ( handledEvents . Contains ( e ) )
395386 {
396- throw new InvalidOperationException ( $ "declared multiple handlers for '{ e } '") ;
387+ throw new InvalidOperationException ( $ "declared multiple handlers for event '{ e } '") ;
397388 }
398389 }
399390
@@ -404,7 +395,7 @@ private static void CheckEventHandlerAlreadyInherited(Type e, Type baseState, Ha
404395 {
405396 if ( handledEvents . Contains ( e ) )
406397 {
407- throw new InvalidOperationException ( $ "inherited multiple handlers for '{ e } ' from state '{ baseState } '") ;
398+ throw new InvalidOperationException ( $ "inherited multiple handlers for event '{ e } ' from state '{ baseState } '") ;
408399 }
409400 }
410401 }
0 commit comments