15
15
using System . Net . Http ;
16
16
using System . Reflection ;
17
17
using System . Reflection . Emit ;
18
- using static System . StringComparison ;
19
18
#if WEBAPI
20
19
using IActionResult = System . Web . Http . IHttpActionResult ;
21
20
#endif
26
25
public static partial class TypeExtensions
27
26
{
28
27
static readonly Type VoidType = typeof ( void ) ;
29
- static readonly Type ActionResultType = typeof ( IActionResult ) ;
30
28
static readonly Type HttpResponseType = typeof ( HttpResponseMessage ) ;
31
29
static readonly Type IEnumerableOfT = typeof ( IEnumerable < > ) ;
32
30
static readonly Type ODataValueOfT = typeof ( ODataValue < > ) ;
33
31
static readonly Type SingleResultOfT = typeof ( SingleResult < > ) ;
32
+ static readonly Type ActionResultType = typeof ( IActionResult ) ;
33
+ #if ! WEBAPI
34
+ static readonly Type ActionResultOfT = typeof ( ActionResult < > ) ;
35
+ #endif
34
36
35
37
/// <summary>
36
38
/// Substitutes the specified type, if required.
@@ -157,7 +159,11 @@ internal static Type ExtractInnerType( this Type type )
157
159
158
160
var typeArg = typeArgs [ 0 ] ;
159
161
160
- if ( typeDef . IsDelta ( ) || typeDef . Equals ( ODataValueOfT ) || typeDef . IsActionResult ( ) || typeDef . Equals ( SingleResultOfT ) )
162
+ #if WEBAPI
163
+ if ( typeDef . IsDelta ( ) || typeDef . IsODataValue ( ) || typeDef . IsSingleResult ( ) )
164
+ #else
165
+ if ( typeDef . IsDelta ( ) || typeDef . IsODataValue ( ) || typeDef . IsSingleResult ( ) || typeDef . IsActionResult ( ) )
166
+ #endif
161
167
{
162
168
return typeArg ;
163
169
}
@@ -189,7 +195,11 @@ static bool IsSubstitutableGeneric( Type type, Stack<Type> openTypes, out Type i
189
195
190
196
var typeArg = typeArgs [ 0 ] ;
191
197
192
- if ( typeDef . Equals ( IEnumerableOfT ) || typeDef . IsDelta ( ) || typeDef . Equals ( ODataValueOfT ) || typeDef . IsActionResult ( ) || typeDef . Equals ( SingleResultOfT ) )
198
+ #if WEBAPI
199
+ if ( typeDef . Equals ( IEnumerableOfT ) || typeDef . IsDelta ( ) || typeDef . IsODataValue ( ) || typeDef . IsSingleResult ( ) )
200
+ #else
201
+ if ( typeDef . Equals ( IEnumerableOfT ) || typeDef . IsDelta ( ) || typeDef . IsODataValue ( ) || typeDef . IsSingleResult ( ) || typeDef . IsActionResult ( ) )
202
+ #endif
193
203
{
194
204
innerType = typeArg ;
195
205
}
@@ -284,12 +294,18 @@ internal static bool IsEnumerable( this Type type, out Type itemType )
284
294
return false ;
285
295
}
286
296
287
- static bool IsActionResult ( this Type type ) =>
288
- type . IsGenericType &&
289
- type . GetGenericTypeDefinition ( ) . FullName . Equals ( "Microsoft.AspNetCore.Mvc.ActionResult`1" , Ordinal ) ;
297
+ static bool IsSingleResult ( this Type type ) => type . Is ( SingleResultOfT ) ;
298
+
299
+ static bool IsODataValue ( this Type type ) => type . Is ( ODataValueOfT ) ;
290
300
291
- static bool IsSingleResult ( this Type type ) => SingleResultOfT . IsAssignableFrom ( type ) ;
301
+ static bool Is ( this Type type , Type typeDefinition ) => type . IsGenericType && type . GetGenericTypeDefinition ( ) . Equals ( typeDefinition ) ;
292
302
303
+ #if WEBAPI
304
+ static bool ShouldExtractInnerType ( this Type type ) => type . IsDelta ( ) || type . IsSingleResult ( ) ;
305
+ #else
293
306
static bool ShouldExtractInnerType ( this Type type ) => type . IsDelta ( ) || type . IsSingleResult ( ) || type . IsActionResult ( ) ;
307
+
308
+ static bool IsActionResult ( this Type type ) => type . Is ( ActionResultOfT ) ;
309
+ #endif
294
310
}
295
311
}
0 commit comments