Skip to content

Commit 351bbdb

Browse files
Use pattern matching
1 parent d73194d commit 351bbdb

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/MakingSense.AspNetCore.HypermediaApi/ApiMappers/ApiMapperExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,16 @@ public static TOut Map<TIn, TOut>(this IApiMapper<TIn, TOut> mapper, TIn input)
5959
public static IEnumerable<TOut> Map<TIn, TOut>(this IApiMapper<TIn, TOut> mapper, IEnumerable<TIn> inputEnumerable)
6060
where TOut : class, new()
6161
{
62-
var queryableProyector = mapper as IQueryableMapper<TIn, TOut>;
6362
return
64-
queryableProyector != null ? queryableProyector.Map(inputEnumerable.AsQueryable())
63+
mapper is IQueryableMapper<TIn, TOut> queryableProyector ? queryableProyector.Map(inputEnumerable.AsQueryable())
6564
: inputEnumerable.Select(x => mapper.Map(x));
6665
}
6766

6867
public static IEnumerable<TOut> Map<TIn, TOut>(this IApiMapper<TIn, TOut> mapper, IQueryable<TIn> inputQueryable)
6968
where TOut : class, new()
7069
{
71-
var queryableProyector = mapper as IQueryableMapper<TIn, TOut>;
7270
return
73-
queryableProyector != null ? queryableProyector.Map(inputQueryable)
71+
mapper is IQueryableMapper<TIn, TOut> queryableProyector ? queryableProyector.Map(inputQueryable)
7472
: inputQueryable.AsEnumerable().Select(x => mapper.Map(x));
7573
}
7674

src/MakingSense.AspNetCore.HypermediaApi/Linking/BaseLinkHelper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ public Maybe<Link> ToAction(MethodInfo method, ReadOnlyCollection<Expression> ar
6767
var wrappedValues = Enumerable.Range(0, arguments.Count).Select(x =>
6868
{
6969
var argument = arguments[x];
70-
var unaryExpression = argument as UnaryExpression;
7170
TemplateParameter value;
7271

73-
if (unaryExpression != null && unaryExpression.Operand.Type.GetTypeInfo().IsSubclassOf(typeof(TemplateParameter)))
72+
if (argument is UnaryExpression unaryExpression && unaryExpression.Operand.Type.GetTypeInfo().IsSubclassOf(typeof(TemplateParameter)))
7473
{
7574
value = Expression.Lambda(unaryExpression.Operand).Compile().DynamicInvoke() as TemplateParameter;
7675
}

0 commit comments

Comments
 (0)