Skip to content

Commit a3a1216

Browse files
committed
Unified place for string constants instead of nameofs here and there
- remove some of unused cached MethodInfos
1 parent 3f5b130 commit a3a1216

File tree

4 files changed

+62
-26
lines changed

4 files changed

+62
-26
lines changed

Orm/Xtensive.Orm/Orm/Linq/Translator.Expressions.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ protected override Expression VisitMethodCall(MethodCallExpression mc)
463463
return VisitQuerySingle(mc);
464464
}
465465

466-
throw new InvalidOperationException(String.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)));
466+
throw new InvalidOperationException(string.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)));
467467
}
468468
// Visit QueryEndpoint.
469469
if (methodDeclaringType == WellKnownOrmTypes.QueryEndpoint) {
@@ -498,33 +498,33 @@ protected override Expression VisitMethodCall(MethodCallExpression mc)
498498
return VisitSequence(mc.Arguments[0].StripQuotes().Body, mc);
499499
}
500500

501-
throw new InvalidOperationException(String.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)));
501+
throw new InvalidOperationException(string.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)));
502502
}
503503
#pragma warning restore 612,618
504504

505505
// Visit Queryable extensions.
506506
if (methodDeclaringType == typeof(QueryableExtensions)) {
507507
return methodName switch {
508-
nameof(QueryableExtensions.LeftJoin) => VisitLeftJoin(mc),
509-
"In" => VisitIn(mc),
510-
nameof(QueryableExtensions.Lock) => VisitLock(mc),
511-
nameof(QueryableExtensions.Take) => VisitTake(mc.Arguments[0], mc.Arguments[1]),
512-
nameof(QueryableExtensions.Skip) => VisitSkip(mc.Arguments[0], mc.Arguments[1]),
513-
nameof(QueryableExtensions.ElementAt) => VisitElementAt(mc.Arguments[0], mc.Arguments[1], context.IsRoot(mc), method.ReturnType, false),
514-
nameof(QueryableExtensions.ElementAtOrDefault) => VisitElementAt(mc.Arguments[0], mc.Arguments[1], context.IsRoot(mc), method.ReturnType, true),
515-
nameof(QueryableExtensions.Count) => VisitAggregate(mc.Arguments[0], method, null, context.IsRoot(mc), mc),
516-
nameof(QueryableExtensions.Tag) => VisitTag(mc),
517-
_ => throw new InvalidOperationException(String.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)))
508+
Reflection.WellKnown.QueryableExtensions.LeftJoin => VisitLeftJoin(mc),
509+
Reflection.WellKnown.QueryableExtensions.In => VisitIn(mc),
510+
Reflection.WellKnown.QueryableExtensions.Lock => VisitLock(mc),
511+
Reflection.WellKnown.QueryableExtensions.Take => VisitTake(mc.Arguments[0], mc.Arguments[1]),
512+
Reflection.WellKnown.QueryableExtensions.Skip => VisitSkip(mc.Arguments[0], mc.Arguments[1]),
513+
Reflection.WellKnown.QueryableExtensions.ElementAt => VisitElementAt(mc.Arguments[0], mc.Arguments[1], context.IsRoot(mc), method.ReturnType, false),
514+
Reflection.WellKnown.QueryableExtensions.ElementAtOrDefault => VisitElementAt(mc.Arguments[0], mc.Arguments[1], context.IsRoot(mc), method.ReturnType, true),
515+
Reflection.WellKnown.QueryableExtensions.Count => VisitAggregate(mc.Arguments[0], method, null, context.IsRoot(mc), mc),
516+
Reflection.WellKnown.QueryableExtensions.Tag => VisitTag(mc),
517+
_ => throw new InvalidOperationException(string.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)))
518518
};
519519
}
520520
// Visit Collection extensions
521521
if (methodDeclaringType == typeof(CollectionExtensionsEx)) {
522522
switch (methodName) {
523-
case nameof(CollectionExtensionsEx.ContainsAny):
523+
case Reflection.WellKnown.CollectionExtensions.ContainsAny:
524524
return VisitContainsAny(mc.Arguments[0], mc.Arguments[1], context.IsRoot(mc), method.GetGenericArguments()[0]);
525-
case nameof(CollectionExtensionsEx.ContainsAll):
525+
case Reflection.WellKnown.CollectionExtensions.ContainsAll:
526526
return VisitContainsAll(mc.Arguments[0], mc.Arguments[1], context.IsRoot(mc), method.GetGenericArguments()[0]);
527-
case nameof(CollectionExtensionsEx.ContainsNone):
527+
case Reflection.WellKnown.CollectionExtensions.ContainsNone:
528528
return VisitContainsNone(mc.Arguments[0], mc.Arguments[1], context.IsRoot(mc), method.GetGenericArguments()[0]);
529529
}
530530
}
@@ -535,16 +535,16 @@ protected override Expression VisitMethodCall(MethodCallExpression mc)
535535
// IList.Contains
536536
// List.Contains
537537
// Array.Contains
538-
ParameterInfo[] parameters = method.GetParameters();
539-
if (methodName=="Contains" && parameters.Length==1)
538+
var parameters = method.GetParameters();
539+
if (methodName == nameof(ICollection<int>.Contains) && parameters.Length == 1)
540540
return VisitContains(mc.Object, mc.Arguments[0], false);
541541
}
542542

543543
var result = base.VisitMethodCall(mc);
544544
if (result != mc && result.NodeType == ExpressionType.Call) {
545545
var visitedMethodCall = (MethodCallExpression) result;
546546
if (visitedMethodCall.Arguments.Any(arg => arg.IsProjection()))
547-
throw new InvalidOperationException(String.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)));
547+
throw new InvalidOperationException(string.Format(Strings.ExMethodCallExpressionXIsNotSupported, mc.ToString(true)));
548548
}
549549
return result;
550550
}

Orm/Xtensive.Orm/Orm/Linq/WellKnownMembers.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ public static class Enumerable
198198
public static readonly MethodInfo Cast = GetMethod(typeof(System.Linq.Enumerable), nameof(System.Linq.Enumerable.Cast), 1, 1);
199199
}
200200

201-
public static class Collection
202-
{
203-
// Collection extensions
204-
public static readonly MethodInfo ExtensionContainsAll = GetMethod(typeof(CollectionExtensionsEx), nameof(CollectionExtensionsEx.ContainsAll), 1, 2);
205-
public static readonly MethodInfo ExtensionContainsAny = GetMethod(typeof(CollectionExtensionsEx), nameof(CollectionExtensionsEx.ContainsAny), 1, 2);
206-
public static readonly MethodInfo ExtensionContainsNone = GetMethod(typeof(CollectionExtensionsEx), nameof(CollectionExtensionsEx.ContainsNone), 1, 2);
207-
}
208-
209201
// IEntity
210202
public static readonly PropertyInfo IEntityKey = WellKnownOrmInterfaces.Entity.GetProperty(WellKnown.KeyFieldName);
211203
public static readonly PropertyInfo TypeId = WellKnownOrmInterfaces.Entity.GetProperty(WellKnown.TypeIdFieldName);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (C) 2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
namespace Xtensive.Reflection
6+
{
7+
public partial class WellKnown
8+
{
9+
/// <summary>
10+
/// Various well-known constants related to <see cref="Core.CollectionExtensionsEx" />
11+
/// </summary>
12+
public static class CollectionExtensions
13+
{
14+
public const string ContainsAll = nameof(Core.CollectionExtensionsEx.ContainsAll);
15+
public const string ContainsAny = nameof(Core.CollectionExtensionsEx.ContainsAny);
16+
public const string ContainsNone = nameof(Core.CollectionExtensionsEx.ContainsNone);
17+
}
18+
}
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
namespace Xtensive.Reflection
6+
{
7+
public partial class WellKnown
8+
{
9+
/// <summary>
10+
/// Various well-known constants related to <see cref="Orm.QueryableExtensions" />
11+
/// </summary>
12+
public static class QueryableExtensions
13+
{
14+
public const string Count = nameof(Orm.QueryableExtensions.Count);
15+
public const string LeftJoin = nameof(Orm.QueryableExtensions.LeftJoin);
16+
public const string Lock = nameof(Orm.QueryableExtensions.Lock);
17+
public const string Take = nameof(Orm.QueryableExtensions.Take);
18+
public const string Skip = nameof(Orm.QueryableExtensions.Skip);
19+
public const string ElementAt = nameof(Orm.QueryableExtensions.ElementAt);
20+
public const string ElementAtOrDefault = nameof(Orm.QueryableExtensions.ElementAtOrDefault);
21+
public const string Tag = nameof(Orm.QueryableExtensions.Tag);
22+
public const string In = nameof(Orm.QueryableExtensions.In);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)