File tree Expand file tree Collapse file tree
OnTopic.AspNetCore.Mvc/_filters Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,9 +62,7 @@ public override void OnActionExecuting(ActionExecutingContext context) {
6262 /*------------------------------------------------------------------------------------------------------------------------
6363 | Validate controller
6464 \-----------------------------------------------------------------------------------------------------------------------*/
65- var controller = context . Controller as TopicController ;
66-
67- if ( controller is null ) {
65+ if ( context . Controller is not TopicController controller ) {
6866 throw new InvalidOperationException (
6967 $ "The { nameof ( TopicResponseCacheAttribute ) } can only be applied to a controller deriving from { nameof ( TopicController ) } ."
7068 ) ;
Original file line number Diff line number Diff line change @@ -60,23 +60,19 @@ public override void OnActionExecuting(ActionExecutingContext context) {
6060 Contract . Requires ( context , nameof ( context ) ) ;
6161
6262 /*------------------------------------------------------------------------------------------------------------------------
63- | Establish variables
63+ | Validate controller
6464 \-----------------------------------------------------------------------------------------------------------------------*/
65- var controller = context . Controller as TopicController ;
66- var currentTopic = controller ? . CurrentTopic ;
67-
68- /*------------------------------------------------------------------------------------------------------------------------
69- | Validate context
70- \-----------------------------------------------------------------------------------------------------------------------*/
71- if ( controller is null ) {
65+ if ( context . Controller is not TopicController controller ) {
7266 throw new InvalidOperationException (
73- $ "The { nameof ( ValidateTopicAttribute ) } can only be applied to a controller deriving from { nameof ( TopicController ) } ."
67+ $ "The { nameof ( TopicResponseCacheAttribute ) } can only be applied to a controller deriving from { nameof ( TopicController ) } ."
7468 ) ;
7569 }
7670
7771 /*------------------------------------------------------------------------------------------------------------------------
78- | Handle exceptions
72+ | Validate current topic
7973 \-----------------------------------------------------------------------------------------------------------------------*/
74+ var currentTopic = controller . CurrentTopic ;
75+
8076 if ( currentTopic is null ) {
8177 if ( ! AllowNull ) {
8278 context . Result = controller . NotFound ( "There is no topic associated with this path." ) ;
You can’t perform that action at this time.
0 commit comments