Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ internal static class EnumerableMethod
private static readonly MethodInfo __range;
private static readonly MethodInfo __repeat;
private static readonly MethodInfo __reverse;
private static readonly MethodInfo __reverseWithArray; // will be null on target frameworks that don't have this method
private static readonly MethodInfo __select;
private static readonly MethodInfo __selectMany;
private static readonly MethodInfo __selectManyWithCollectionSelectorAndResultSelector;
Expand Down Expand Up @@ -195,6 +196,12 @@ internal static class EnumerableMethod
// static constructor
static EnumerableMethod()
{
#if NET10_OR_GREATER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This #if def does not make any sense to me. We do not have any target defining it, so the code is never going to be executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense if you consider that very soon we will be adding net10 as a target.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but for now it's a dead-code. Why do we need to add this code to repo NOW?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've came across this question in CSHARP-5665 wanting to use CommonPrefixLength. I decided not to have a dead and untested code, and will note it as a future improvement for net10 target. I suggest doing the same here.

Also we don't have an official date to support net10 yet.

__reverseWithArray = ReflectionInfo.Method(array source) => source.Reverse());
#else
__reverseWithArray = GetReverseWithArrayMethodInfo(); // support users running net10 even though we don't target net10 yet
#endif

__aggregateWithFunc = ReflectionInfo.Method((IEnumerable<object> source, Func<object, object, object> func) => source.Aggregate(func));
__aggregateWithSeedAndFunc = ReflectionInfo.Method((IEnumerable<object> source, object seed, Func<object, object, object> func) => source.Aggregate(seed, func));
__aggregateWithSeedFuncAndResultSelector = ReflectionInfo.Method((IEnumerable<object> source, object seed, Func<object, object, object> func, Func<object, object> resultSelector) => source.Aggregate(seed, func, resultSelector));
Expand Down Expand Up @@ -481,6 +488,7 @@ static EnumerableMethod()
public static MethodInfo Range => __range;
public static MethodInfo Repeat => __repeat;
public static MethodInfo Reverse => __reverse;
public static MethodInfo ReverseWithArray => __reverseWithArray;
public static MethodInfo Select => __select;
public static MethodInfo SelectMany => __selectMany;
public static MethodInfo SelectManyWithCollectionSelectorAndResultSelector => __selectManyWithCollectionSelectorAndResultSelector;
Expand Down Expand Up @@ -613,5 +621,28 @@ public static MethodInfo MakeWhere(Type tsource)
{
return __where.MakeGenericMethod(tsource);
}

#if !NET10_OR_GREATER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this code will be always included, as we have no configuration to have NET10_OR_GREATER defined.

private static MethodInfo GetReverseWithArrayMethodInfo()
{
// returns null on target frameworks that don't have this method
return
typeof(Enumerable)
.GetMethods()
.SingleOrDefault(m =>
m.IsPublic &&
m.IsStatic &&
m.Name == "Reverse" &&
m.IsGenericMethodDefinition &&
m.GetGenericArguments() is var genericArguments &&
genericArguments.Length == 1 &&
genericArguments[0] is var tsource &&
m.ReturnType == typeof(IEnumerable<>).MakeGenericType(tsource) &&
m.GetParameters() is var parameters &&
parameters.Length == 1 &&
parameters[0] is var sourceParameter &&
sourceParameter.ParameterType == tsource.MakeArrayType());
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal static class ReverseMethodToAggregationExpressionTranslator
private static readonly MethodInfo[] __reverseMethods =
{
EnumerableMethod.Reverse,
EnumerableMethod.ReverseWithArray,
QueryableMethod.Reverse
};

Expand Down