From 50838e3323b729ac991e1a5eb4392fd523069dd6 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Mon, 3 Jan 2022 12:55:13 +0100 Subject: [PATCH] Remove other reflection wrappers --- .../Extensions/CosmosQueryableExtensions.cs | 2 +- ...yExpressionTranslatingExpressionVisitor.cs | 8 +-- .../Query/Internal/InMemoryQueryExpression.cs | 6 +- ...yableMethodTranslatingExpressionVisitor.cs | 2 +- ...erExpressionProcessingExpressionVisitor.cs | 10 +-- ...ryShapedQueryCompilingExpressionVisitor.cs | 2 +- .../RelationalQueryableExtensions.cs | 4 +- .../Query/Internal/CollateTranslator.cs | 2 +- ...ionalProjectionBindingExpressionVisitor.cs | 2 +- ...yableMethodTranslatingExpressionVisitor.cs | 2 +- ...sitor.ShaperProcessingExpressionVisitor.cs | 28 ++++----- ...lationalSqlTranslatingExpressionVisitor.cs | 8 +-- .../Query/SqlExpressions/SelectExpression.cs | 4 +- ...erverGeometryCollectionMemberTranslator.cs | 3 +- ...erverGeometryCollectionMethodTranslator.cs | 2 +- .../SqlServerGeometryMemberTranslator.cs | 34 +++++----- .../SqlServerLineStringMemberTranslator.cs | 10 +-- ...qlServerMultiLineStringMemberTranslator.cs | 3 +- .../SqlServerPointMemberTranslator.cs | 12 ++-- .../SqlServerPolygonMemberTranslator.cs | 6 +- .../Internal/SqliteGlobMethodTranslator.cs | 2 +- .../Internal/SqliteHexMethodTranslator.cs | 2 +- .../Query/Internal/SqliteMathTranslator.cs | 62 +++++++++---------- .../Query/Internal/SqliteRandomTranslator.cs | 4 +- .../Internal/SqliteSubstrMethodTranslator.cs | 6 +- ...qliteGeometryCollectionMemberTranslator.cs | 3 +- ...qliteGeometryCollectionMethodTranslator.cs | 2 +- .../SqliteGeometryMemberTranslator.cs | 34 +++++----- .../SqliteLineStringMemberTranslator.cs | 10 +-- .../SqliteMultiLineStringMemberTranslator.cs | 3 +- .../Internal/SqlitePointMemberTranslator.cs | 8 +-- .../Internal/SqlitePolygonMemberTranslator.cs | 4 +- .../Internal/IdentityMapFactoryFactory.cs | 2 +- .../Internal/InternalEntityEntry.cs | 10 +-- .../Internal/SnapshotFactoryFactory.cs | 2 +- src/EFCore/ChangeTracking/ValueComparer`.cs | 2 +- src/EFCore/EF.cs | 2 +- .../EntityFrameworkQueryableExtensions.cs | 33 +++++----- .../Internal/ExpressionExtensions.cs | 3 +- .../Infrastructure/ExpressionExtensions.cs | 2 +- src/EFCore/Internal/DbSetSource.cs | 2 +- src/EFCore/Internal/EntityFinderSource.cs | 2 +- .../Internal/ManyToManyLoaderFactory.cs | 2 +- ...figurationEntityTypeAttributeConvention.cs | 4 +- src/EFCore/Metadata/Internal/PropertyBase.cs | 2 +- src/EFCore/Query/EntityShaperExpression.cs | 2 +- .../Query/EvaluatableExpressionFilter.cs | 12 ++-- ...ingExpressionVisitor.ExpressionVisitors.cs | 16 ++--- .../NavigationExpandingExpressionVisitor.cs | 14 ++--- src/EFCore/Query/QueryCompilationContext.cs | 2 +- .../ShapedQueryCompilingExpressionVisitor.cs | 16 ++--- src/Shared/SharedTypeExtensions.cs | 41 ------------ 52 files changed, 214 insertions(+), 247 deletions(-) diff --git a/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs index 44afcde741c..4cc9ffd2ddf 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore; public static class CosmosQueryableExtensions { internal static readonly MethodInfo WithPartitionKeyMethodInfo - = typeof(CosmosQueryableExtensions).GetRequiredDeclaredMethod(nameof(WithPartitionKey)); + = typeof(CosmosQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(WithPartitionKey))!; /// /// Specify the partition key for partition used for the query. Required when using diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 423f08328c8..11aa5997513 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -23,13 +23,13 @@ public class InMemoryExpressionTranslatingExpressionVisitor : ExpressionVisitor private static readonly MemberInfo ValueBufferIsEmpty = typeof(ValueBuffer).GetMember(nameof(ValueBuffer.IsEmpty))[0]; private static readonly MethodInfo ParameterValueExtractorMethod = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterValueExtractor)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterValueExtractor))!; private static readonly MethodInfo ParameterListValueExtractorMethod = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterListValueExtractor)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterListValueExtractor))!; private static readonly MethodInfo GetParameterValueMethodInfo = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(GetParameterValue)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(GetParameterValue))!; private static readonly MethodInfo LikeMethodInfo = typeof(DbFunctionsExtensions).GetRuntimeMethod( nameof(DbFunctionsExtensions.Like), new[] { typeof(DbFunctions), typeof(string), typeof(string) })!; @@ -44,7 +44,7 @@ public class InMemoryExpressionTranslatingExpressionVisitor : ExpressionVisitor nameof(Random.NextDouble), Type.EmptyTypes)!; private static readonly MethodInfo InMemoryLikeMethodInfo = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InMemoryLike)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InMemoryLike))!; // Regex special chars defined here: // https://msdn.microsoft.com/en-us/library/4edbef7e(v=vs.110).aspx diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs index 47efb59d618..31b864eb51f 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs @@ -18,7 +18,7 @@ public partial class InMemoryQueryExpression : Expression, IPrintableExpression = typeof(ValueBuffer).GetConstructors().Single(ci => ci.GetParameters().Length == 1); private static readonly PropertyInfo ValueBufferCountMemberInfo - = typeof(ValueBuffer).GetRequiredProperty(nameof(ValueBuffer.Count)); + = typeof(ValueBuffer).GetTypeInfo().GetProperty(nameof(ValueBuffer.Count))!; private static readonly MethodInfo LeftJoinMethodInfo = typeof(InMemoryQueryExpression).GetTypeInfo() .GetDeclaredMethods(nameof(LeftJoin)).Single(mi => mi.GetParameters().Length == 6); @@ -889,8 +889,8 @@ private static Expression GetGroupingKey(Expression key, List groupi bool innerNullable) { var transparentIdentifierType = TransparentIdentifierFactory.Create(outerShaperExpression.Type, innerShaperExpression.Type); - var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var outerClientEval = _clientProjections.Count > 0; var innerClientEval = innerQueryExpression._clientProjections.Count > 0; var resultSelectorExpressions = new List(); diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 69c4ea75875..00f06a3641f 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -1352,7 +1352,7 @@ private ShapedQueryExpression TranslateTwoParameterSelector(ShapedQueryExpressio Type transparentIdentifierType, Expression targetExpression, string fieldName) - => Expression.Field(targetExpression, transparentIdentifierType.GetRequiredDeclaredField(fieldName)); + => Expression.Field(targetExpression, transparentIdentifierType.GetTypeInfo().GetDeclaredField(fieldName)!); private ShapedQueryExpression? TranslateScalarAggregate( ShapedQueryExpression source, diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs index 63ce00d833d..fddb9841612 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs @@ -10,19 +10,19 @@ public partial class InMemoryShapedQueryCompilingExpressionVisitor private sealed class ShaperExpressionProcessingExpressionVisitor : ExpressionVisitor { private static readonly MethodInfo IncludeReferenceMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(IncludeReference)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(IncludeReference))!; private static readonly MethodInfo IncludeCollectionMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(IncludeCollection)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(IncludeCollection))!; private static readonly MethodInfo MaterializeCollectionMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(MaterializeCollection)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(MaterializeCollection))!; private static readonly MethodInfo MaterializeSingleResultMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(MaterializeSingleResult)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(MaterializeSingleResult))!; private static readonly MethodInfo CollectionAccessorAddMethodInfo - = typeof(IClrCollectionAccessor).GetRequiredDeclaredMethod(nameof(IClrCollectionAccessor.Add)); + = typeof(IClrCollectionAccessor).GetTypeInfo().GetDeclaredMethod(nameof(IClrCollectionAccessor.Add))!; private readonly InMemoryShapedQueryCompilingExpressionVisitor _inMemoryShapedQueryCompilingExpressionVisitor; private readonly bool _tracking; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs index f269e02b94c..20983a58665 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs @@ -71,7 +71,7 @@ protected override Expression VisitShapedQuery(ShapedQueryExpression shapedQuery } private static readonly MethodInfo TableMethodInfo - = typeof(InMemoryShapedQueryCompilingExpressionVisitor).GetRequiredDeclaredMethod(nameof(Table)); + = typeof(InMemoryShapedQueryCompilingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(Table))!; private static IEnumerable Table( QueryContext queryContext, diff --git a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs index 55fb2319a48..03670e2e7de 100644 --- a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs @@ -191,7 +191,7 @@ public static DbCommand CreateDbCommand(this IQueryable source) : source; internal static readonly MethodInfo AsSingleQueryMethodInfo - = typeof(RelationalQueryableExtensions).GetRequiredDeclaredMethod(nameof(AsSingleQuery)); + = typeof(RelationalQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsSingleQuery))!; /// /// Returns a new query which is configured to load the collections in the query results through separate database queries. @@ -223,5 +223,5 @@ public static DbCommand CreateDbCommand(this IQueryable source) : source; internal static readonly MethodInfo AsSplitQueryMethodInfo - = typeof(RelationalQueryableExtensions).GetRequiredDeclaredMethod(nameof(AsSplitQuery)); + = typeof(RelationalQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsSplitQuery))!; } diff --git a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs index 8b923532278..eeef6da8c31 100644 --- a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class CollateTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo - = typeof(RelationalDbFunctionsExtensions).GetRequiredMethod(nameof(RelationalDbFunctionsExtensions.Collate)); + = typeof(RelationalDbFunctionsExtensions).GetMethod(nameof(RelationalDbFunctionsExtensions.Collate))!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs index 8e135846dfa..7ee095e5b72 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class RelationalProjectionBindingExpressionVisitor : ExpressionVisitor { private static readonly MethodInfo GetParameterValueMethodInfo - = typeof(RelationalProjectionBindingExpressionVisitor).GetRequiredDeclaredMethod(nameof(GetParameterValue)); + = typeof(RelationalProjectionBindingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(GetParameterValue))!; private readonly RelationalQueryableMethodTranslatingExpressionVisitor _queryableMethodTranslatingExpressionVisitor; private readonly RelationalSqlTranslatingExpressionVisitor _sqlTranslator; diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index f2b957340bb..619c463a438 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -1350,7 +1350,7 @@ private ShapedQueryExpression TranslateTwoParameterSelector(ShapedQueryExpressio Type transparentIdentifierType, Expression targetExpression, string fieldName) - => Expression.Field(targetExpression, transparentIdentifierType.GetRequiredDeclaredField(fieldName)); + => Expression.Field(targetExpression, transparentIdentifierType.GetTypeInfo().GetDeclaredField(fieldName)!); private static void HandleGroupByForAggregate(SelectExpression selectExpression, bool eraseProjection = false) { diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs index a3d429fae9e..7dba5391654 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs @@ -21,7 +21,7 @@ private sealed class ShaperProcessingExpressionVisitor : ExpressionVisitor typeof(DbDataReader).GetRuntimeMethod(nameof(DbDataReader.GetFieldValue), new[] { typeof(int) })!; private static readonly MethodInfo ThrowReadValueExceptionMethod = - typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ThrowReadValueException)); + typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ThrowReadValueException))!; // Coordinating results private static readonly MemberInfo ResultContextValuesMemberInfo @@ -32,43 +32,43 @@ private sealed class ShaperProcessingExpressionVisitor : ExpressionVisitor // Performing collection materialization private static readonly MethodInfo IncludeReferenceMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(IncludeReference)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(IncludeReference))!; private static readonly MethodInfo InitializeIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeIncludeCollection))!; private static readonly MethodInfo PopulateIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateIncludeCollection))!; private static readonly MethodInfo InitializeSplitIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeSplitIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeSplitIncludeCollection))!; private static readonly MethodInfo PopulateSplitIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitIncludeCollection))!; private static readonly MethodInfo PopulateSplitIncludeCollectionAsyncMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitIncludeCollectionAsync)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitIncludeCollectionAsync))!; private static readonly MethodInfo InitializeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeCollection))!; private static readonly MethodInfo PopulateCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateCollection))!; private static readonly MethodInfo InitializeSplitCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeSplitCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeSplitCollection))!; private static readonly MethodInfo PopulateSplitCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitCollection))!; private static readonly MethodInfo PopulateSplitCollectionAsyncMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitCollectionAsync)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitCollectionAsync))!; private static readonly MethodInfo TaskAwaiterMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(TaskAwaiter)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(TaskAwaiter))!; private static readonly MethodInfo CollectionAccessorAddMethodInfo - = typeof(IClrCollectionAccessor).GetRequiredDeclaredMethod(nameof(IClrCollectionAccessor.Add)); + = typeof(IClrCollectionAccessor).GetTypeInfo().GetDeclaredMethod(nameof(IClrCollectionAccessor.Add))!; private readonly RelationalShapedQueryCompilingExpressionVisitor _parentVisitor; private readonly ISet? _tags; diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index 2435b8f822b..90cac3419c2 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -21,11 +21,11 @@ public class RelationalSqlTranslatingExpressionVisitor : ExpressionVisitor { private const string RuntimeParameterPrefix = QueryCompilationContext.QueryParameterPrefix + "entity_equality_"; - private static readonly MethodInfo ParameterValueExtractorMethid = - typeof(RelationalSqlTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterValueExtractor)); + private static readonly MethodInfo ParameterValueExtractorMethod = + typeof(RelationalSqlTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterValueExtractor))!; private static readonly MethodInfo ParameterListValueExtractorMethod = - typeof(RelationalSqlTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterListValueExtractor)); + typeof(RelationalSqlTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterListValueExtractor))!; private static readonly MethodInfo StringEqualsWithStringComparison = typeof(string).GetRuntimeMethod(nameof(string.Equals), new[] { typeof(string), typeof(StringComparison) })!; @@ -1266,7 +1266,7 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal): var lambda = Expression.Lambda( Expression.Call( - ParameterValueExtractorMethid.MakeGenericMethod(property.ClrType.MakeNullable()), + ParameterValueExtractorMethod.MakeGenericMethod(property.ClrType.MakeNullable()), QueryCompilationContext.QueryContextParameter, Expression.Constant(sqlParameterExpression.Name, typeof(string)), Expression.Constant(property, typeof(IProperty))), diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index f11cffd8480..8ed9cd1dda9 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -1913,8 +1913,8 @@ private enum JoinType AddJoin(joinType, ref innerSelectExpression, out _, joinPredicate); var transparentIdentifierType = TransparentIdentifierFactory.Create(outerShaper.Type, innerShaper.Type); - var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var outerClientEval = _clientProjections.Count > 0; var innerClientEval = innerSelectExpression._clientProjections.Count > 0; var innerNullable = joinType == JoinType.LeftJoin || joinType == JoinType.OuterApply; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs index fd4ca1f245d..d42e7c6008a 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerGeometryCollectionMemberTranslator : IMemberTranslator { - private static readonly MemberInfo Count = typeof(GeometryCollection).GetRequiredRuntimeProperty(nameof(GeometryCollection.Count)); + private static readonly MemberInfo Count + = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty(nameof(GeometryCollection.Count))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs index 6ea749b71c7..9f8ec2331c5 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerGeometryCollectionMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo Item = typeof(GeometryCollection).GetRequiredRuntimeProperty("Item").GetMethod!; + private static readonly MethodInfo Item = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty("Item")!.GetMethod!; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs index db2ddf5b81b..508c6a70ba0 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs @@ -16,28 +16,30 @@ public class SqlServerGeometryMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Area)), "STArea" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Dimension)), "STDimension" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.GeometryType)), "STGeometryType" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsEmpty)), "STIsEmpty" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsValid)), "STIsValid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Length)), "STLength" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumGeometries)), "STNumGeometries" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumPoints)), "STNumPoints" } + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Area))!, "STArea" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Dimension))!, "STDimension" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.GeometryType))!, "STGeometryType" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsEmpty))!, "STIsEmpty" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsValid))!, "STIsValid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Length))!, "STLength" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumGeometries))!, "STNumGeometries" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumPoints))!, "STNumPoints" } }; private static readonly IDictionary GeometryMemberToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Boundary)), "STBoundary" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Centroid)), "STCentroid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Envelope)), "STEnvelope" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.InteriorPoint)), "STPointOnSurface" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsSimple)), "STIsSimple" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.PointOnSurface)), "STPointOnSurface" } + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Boundary))!, "STBoundary" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Centroid))!, "STCentroid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Envelope))!, "STEnvelope" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.InteriorPoint))!, "STPointOnSurface" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsSimple))!, "STIsSimple" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.PointOnSurface))!, "STPointOnSurface" } }; - private static readonly MemberInfo OgcGeometryType = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.OgcGeometryType)); - private static readonly MemberInfo Srid = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.SRID)); + private static readonly MemberInfo OgcGeometryType + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.OgcGeometryType))!; + private static readonly MemberInfo Srid + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.SRID))!; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs index e3a20c30ec1..8615e1cc6e3 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs @@ -16,11 +16,11 @@ public class SqlServerLineStringMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.Count)), "STNumPoints" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.EndPoint)), "STEndPoint" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsClosed)), "STIsClosed" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.StartPoint)), "STStartPoint" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsRing)), "STIsRing" } + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.Count))!, "STNumPoints" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.EndPoint))!, "STEndPoint" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsClosed))!, "STIsClosed" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.StartPoint))!, "STStartPoint" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsRing))!, "STIsRing" } }; private readonly IRelationalTypeMappingSource _typeMappingSource; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs index 73f580c64a3..59f8598680c 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerMultiLineStringMemberTranslator : IMemberTranslator { - private static readonly MemberInfo IsClosed = typeof(MultiLineString).GetRequiredRuntimeProperty(nameof(MultiLineString.IsClosed)); + private static readonly MemberInfo IsClosed + = typeof(MultiLineString).GetTypeInfo().GetRuntimeProperty(nameof(MultiLineString.IsClosed))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs index 6a6aa9ade5a..5869ccf2ee1 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs @@ -10,20 +10,20 @@ internal class SqlServerPointMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToPropertyName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.M)), "M" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Z)), "Z" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.M))!, "M" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Z))!, "Z" } }; private static readonly IDictionary GeographyMemberToPropertyName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.X)), "Long" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Y)), "Lat" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.X))!, "Long" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Y))!, "Lat" } }; private static readonly IDictionary GeometryMemberToPropertyName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.X)), "STX" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Y)), "STY" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.X))!, "STX" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Y))!, "STY" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs index 09273983c06..1904aba0a7b 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs @@ -14,8 +14,10 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerPolygonMemberTranslator : IMemberTranslator { - private static readonly MemberInfo ExteriorRing = typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.ExteriorRing)); - private static readonly MemberInfo NumInteriorRings = typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.NumInteriorRings)); + private static readonly MemberInfo ExteriorRing + = typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.ExteriorRing))!; + private static readonly MemberInfo NumInteriorRings + = typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.NumInteriorRings))!; private static readonly IDictionary GeometryMemberToFunctionName = new Dictionary { diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs index 61e7e52ac07..2de04affc5c 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteGlobMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod(nameof(SqliteDbFunctionsExtensions.Glob), typeof(DbFunctions), typeof(string), typeof(string)); + .GetMethod(nameof(SqliteDbFunctionsExtensions.Glob), new[] { typeof(DbFunctions), typeof(string), typeof(string) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs index 41b7b57d0d8..68e759f7a85 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteHexMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod(nameof(SqliteDbFunctionsExtensions.Hex), typeof(DbFunctions), typeof(byte[])); + .GetMethod(nameof(SqliteDbFunctionsExtensions.Hex), new[] { typeof(DbFunctions), typeof(byte[]) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs index 51e36965cd8..60c3f13e46e 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs @@ -16,37 +16,37 @@ public class SqliteMathTranslator : IMethodCallTranslator { private static readonly Dictionary SupportedMethods = new() { - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(double)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(float)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(int)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(long)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(sbyte)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(short)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(byte), typeof(byte)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(double), typeof(double)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(float), typeof(float)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(int), typeof(int)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(long), typeof(long)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(sbyte), typeof(sbyte)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(short), typeof(short)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(uint), typeof(uint)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(ushort), typeof(ushort)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(byte), typeof(byte)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(double), typeof(double)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(float), typeof(float)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(int), typeof(int)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(long), typeof(long)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(sbyte), typeof(sbyte)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(short), typeof(short)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(uint), typeof(uint)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(ushort), typeof(ushort)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Round), typeof(double)), "round" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Round), typeof(double), typeof(int)), "round" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Abs), typeof(float)), "abs" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Max), typeof(float), typeof(float)), "max" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Min), typeof(float), typeof(float)), "min" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Round), typeof(float)), "round" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Round), typeof(float), typeof(int)), "round" } + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(double) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(float) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(int) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(long) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(sbyte) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(short) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(byte), typeof(byte) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(double), typeof(double) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(float), typeof(float) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(int), typeof(int) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(long), typeof(long) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(sbyte), typeof(sbyte) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(short), typeof(short) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(uint), typeof(uint) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(ushort), typeof(ushort) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(byte), typeof(byte) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(double), typeof(double) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(float), typeof(float) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(int), typeof(int) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(long), typeof(long) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(sbyte), typeof(sbyte) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(short), typeof(short) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(uint), typeof(uint) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(ushort), typeof(ushort) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double) })!, "round" }, + { typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) })!, "round" }, + { typeof(MathF).GetMethod(nameof(MathF.Abs), new[] { typeof(float) })!, "abs" }, + { typeof(MathF).GetMethod(nameof(MathF.Max), new[] { typeof(float), typeof(float) })!, "max" }, + { typeof(MathF).GetMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "min" }, + { typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float) })!, "round" }, + { typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })!, "round" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs index 8fcc84dfffb..0670c539e9b 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs @@ -13,8 +13,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteRandomTranslator : IMethodCallTranslator { - private static readonly MethodInfo MethodInfo = typeof(DbFunctionsExtensions).GetRequiredMethod( - nameof(DbFunctionsExtensions.Random), typeof(DbFunctions)); + private static readonly MethodInfo MethodInfo + = typeof(DbFunctionsExtensions).GetMethod(nameof(DbFunctionsExtensions.Random), new[] { typeof(DbFunctions) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs index e27b07e3d21..a6455f484d4 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs @@ -14,11 +14,11 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteSubstrMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod(nameof(SqliteDbFunctionsExtensions.Substr), typeof(DbFunctions), typeof(byte[]), typeof(int)); + .GetMethod(nameof(SqliteDbFunctionsExtensions.Substr), new[] { typeof(DbFunctions), typeof(byte[]), typeof(int) })!; private static readonly MethodInfo MethodInfoWithLength = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod( - nameof(SqliteDbFunctionsExtensions.Substr), typeof(DbFunctions), typeof(byte[]), typeof(int), typeof(int)); + .GetMethod( + nameof(SqliteDbFunctionsExtensions.Substr), new[] { typeof(DbFunctions), typeof(byte[]), typeof(int), typeof(int) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs index 6694b6fd799..b6f7fba1ff1 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteGeometryCollectionMemberTranslator : IMemberTranslator { - private static readonly MemberInfo Count = typeof(GeometryCollection).GetRequiredRuntimeProperty(nameof(GeometryCollection.Count)); + private static readonly MemberInfo Count + = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty(nameof(GeometryCollection.Count))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs index ebe9e83a546..ed0fb221f45 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteGeometryCollectionMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo Item = typeof(GeometryCollection).GetRequiredRuntimeProperty("Item").GetMethod!; + private static readonly MethodInfo Item = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty("Item")!.GetMethod!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs index 15245ab15d2..acb882a21bf 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs @@ -16,24 +16,26 @@ public class SqliteGeometryMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Area)), "Area" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Boundary)), "Boundary" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Centroid)), "Centroid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Dimension)), "Dimension" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Envelope)), "Envelope" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.InteriorPoint)), "PointOnSurface" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsEmpty)), "IsEmpty" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsSimple)), "IsSimple" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsValid)), "IsValid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Length)), "GLength" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumGeometries)), "NumGeometries" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumPoints)), "NumPoints" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.PointOnSurface)), "PointOnSurface" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.SRID)), "SRID" } + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Area))!, "Area" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Boundary))!, "Boundary" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Centroid))!, "Centroid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Dimension))!, "Dimension" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Envelope))!, "Envelope" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.InteriorPoint))!, "PointOnSurface" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsEmpty))!, "IsEmpty" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsSimple))!, "IsSimple" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsValid))!, "IsValid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Length))!, "GLength" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumGeometries))!, "NumGeometries" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumPoints))!, "NumPoints" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.PointOnSurface))!, "PointOnSurface" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.SRID))!, "SRID" } }; - private static readonly MemberInfo GeometryType = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.GeometryType)); - private static readonly MemberInfo OgcGeometryType = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.OgcGeometryType)); + private static readonly MemberInfo GeometryType + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.GeometryType))!; + private static readonly MemberInfo OgcGeometryType + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.OgcGeometryType))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs index 1bc0794284a..0dfa4f6527e 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs @@ -17,11 +17,11 @@ public class SqliteLineStringMemberTranslator : IMemberTranslator private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.Count)), "NumPoints" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.EndPoint)), "EndPoint" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsClosed)), "IsClosed" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsRing)), "IsRing" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.StartPoint)), "StartPoint" } + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.Count))!, "NumPoints" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.EndPoint))!, "EndPoint" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsClosed))!, "IsClosed" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsRing))!, "IsRing" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.StartPoint))!, "StartPoint" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs index e5f77718281..3aff3787272 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteMultiLineStringMemberTranslator : IMemberTranslator { - private static readonly MemberInfo IsClosed = typeof(MultiLineString).GetRequiredRuntimeProperty(nameof(MultiLineString.IsClosed)); + private static readonly MemberInfo IsClosed + = typeof(MultiLineString).GetTypeInfo().GetRuntimeProperty(nameof(MultiLineString.IsClosed))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs index f3fa7426055..989c0f8a642 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs @@ -16,10 +16,10 @@ public class SqlitePointMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.M)), "M" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.X)), "X" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Y)), "Y" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Z)), "Z" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.M))!, "M" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.X))!, "X" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Y))!, "Y" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Z))!, "Z" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs index 00c14af90b9..b49727df557 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs @@ -17,8 +17,8 @@ public class SqlitePolygonMemberTranslator : IMemberTranslator private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.ExteriorRing)), "ExteriorRing" }, - { typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.NumInteriorRings)), "NumInteriorRing" } + { typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.ExteriorRing))!, "ExteriorRing" }, + { typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.NumInteriorRings))!, "NumInteriorRing" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs index 89697900cc1..ab9e5768d5d 100644 --- a/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs @@ -21,7 +21,7 @@ public class IdentityMapFactoryFactory /// public virtual Func Create(IKey key) => (Func)typeof(IdentityMapFactoryFactory).GetTypeInfo() - .GetRequiredDeclaredMethod(nameof(CreateFactory)) + .GetDeclaredMethod(nameof(CreateFactory))! .MakeGenericMethod(key.GetKeyType()) .Invoke(null, new object[] { key })!; diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs index 31c0e72b09b..cc0f4bee236 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs @@ -766,7 +766,7 @@ public void MarkUnknown(IProperty property) => _stateData.FlagProperty(property.GetIndex(), PropertyFlag.Unknown, true); internal static readonly MethodInfo ReadShadowValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadShadowValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadShadowValue))!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -778,28 +778,28 @@ private T ReadShadowValue(int shadowIndex) => _shadowValues.GetValue(shadowIndex); internal static readonly MethodInfo ReadOriginalValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadOriginalValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadOriginalValue))!; [UsedImplicitly] private T ReadOriginalValue(IProperty property, int originalValueIndex) => _originalValues.GetValue(this, property, originalValueIndex); internal static readonly MethodInfo ReadRelationshipSnapshotValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadRelationshipSnapshotValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadRelationshipSnapshotValue))!; [UsedImplicitly] private T ReadRelationshipSnapshotValue(IPropertyBase propertyBase, int relationshipSnapshotIndex) => _relationshipsSnapshot.GetValue(this, propertyBase, relationshipSnapshotIndex); internal static readonly MethodInfo ReadStoreGeneratedValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadStoreGeneratedValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadStoreGeneratedValue))!; [UsedImplicitly] private T ReadStoreGeneratedValue(int storeGeneratedIndex) => _storeGeneratedValues.GetValue(storeGeneratedIndex); internal static readonly MethodInfo ReadTemporaryValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadTemporaryValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadTemporaryValue))!; [UsedImplicitly] private T ReadTemporaryValue(int storeGeneratedIndex) diff --git a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs index da9c1bad15f..25654ef3949 100644 --- a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs @@ -262,7 +262,7 @@ protected virtual bool UseEntityVariable => true; private static readonly MethodInfo SnapshotCollectionMethod - = typeof(SnapshotFactoryFactory).GetTypeInfo().GetRequiredDeclaredMethod(nameof(SnapshotCollection)); + = typeof(SnapshotFactoryFactory).GetTypeInfo().GetDeclaredMethod(nameof(SnapshotCollection))!; [UsedImplicitly] private static HashSet? SnapshotCollection(IEnumerable? collection) diff --git a/src/EFCore/ChangeTracking/ValueComparer`.cs b/src/EFCore/ChangeTracking/ValueComparer`.cs index f6b767ebca3..99f743569d1 100644 --- a/src/EFCore/ChangeTracking/ValueComparer`.cs +++ b/src/EFCore/ChangeTracking/ValueComparer`.cs @@ -191,7 +191,7 @@ public ValueComparer(bool favorStructuralComparisons) new[] { lengthVariable, destinationVariable }, Expression.Assign( lengthVariable, - Expression.Property(sourceParameter, typeof(T).GetRequiredProperty(nameof(Array.Length)))), + Expression.Property(sourceParameter, typeof(T).GetTypeInfo().GetProperty(nameof(Array.Length))!)), Expression.Assign( destinationVariable, Expression.NewArrayBounds(typeof(T).GetSequenceType(), lengthVariable)), diff --git a/src/EFCore/EF.cs b/src/EFCore/EF.cs index 29bb70788d4..457cc47efda 100644 --- a/src/EFCore/EF.cs +++ b/src/EFCore/EF.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore; public static partial class EF { internal static readonly MethodInfo PropertyMethod - = typeof(EF).GetRequiredDeclaredMethod(nameof(Property)); + = typeof(EF).GetTypeInfo().GetDeclaredMethod(nameof(Property))!; /// /// References a given property or navigation on an entity instance. This is useful for shadow state properties, for diff --git a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs index 69c9525899d..45593dfe27e 100644 --- a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs +++ b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs @@ -2473,8 +2473,7 @@ IEnumerator IEnumerable.GetEnumerator() #region Auto included navigations internal static readonly MethodInfo IgnoreAutoIncludesMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(IgnoreAutoIncludes)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(IgnoreAutoIncludes))!; /// /// Specifies that the current Entity Framework LINQ query should not have any model-level eager loaded navigations applied. @@ -2501,8 +2500,7 @@ IEnumerator IEnumerable.GetEnumerator() #region Query Filters internal static readonly MethodInfo IgnoreQueryFiltersMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(IgnoreQueryFilters)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(IgnoreQueryFilters))!; /// /// Specifies that the current Entity Framework LINQ query should not have any model-level entity query filters applied. @@ -2530,8 +2528,7 @@ IEnumerator IEnumerable.GetEnumerator() #region Tracking internal static readonly MethodInfo AsNoTrackingMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(AsNoTracking)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsNoTracking))!; /// /// The change tracker will not track any of the entities that are returned from a LINQ query. If the @@ -2572,8 +2569,7 @@ IEnumerator IEnumerable.GetEnumerator() : source; internal static readonly MethodInfo AsNoTrackingWithIdentityResolutionMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(AsNoTrackingWithIdentityResolution)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsNoTrackingWithIdentityResolution))!; /// /// The change tracker will not track any of the entities that are returned from a LINQ query. If the @@ -2691,19 +2687,20 @@ IEnumerator IEnumerable.GetEnumerator() #region Tagging internal static readonly MethodInfo TagWithMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod( - nameof(TagWith), mi => mi.GetParameters().Length == 2 - && mi.GetParameters().Select(p => p.ParameterType) - .SequenceEqual(new[] { typeof(IQueryable<>).MakeGenericType(mi.GetGenericArguments()), typeof(string) })); + = typeof(EntityFrameworkQueryableExtensions).GetMethod(nameof(TagWith), new[] + { + typeof(IQueryable<>).MakeGenericType(Type.MakeGenericMethodParameter(0)), + typeof(string) + })!; internal static readonly MethodInfo TagWithCallSiteMethodInfo = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod( - nameof(TagWithCallSite), mi => mi.GetParameters().Length == 3 - && mi.GetParameters().Select(p => p.ParameterType) - .SequenceEqual( - new[] { typeof(IQueryable<>).MakeGenericType(mi.GetGenericArguments()), typeof(string), typeof(int) })); + .GetMethod(nameof(TagWithCallSite), new[] + { + typeof(IQueryable<>).MakeGenericType(Type.MakeGenericMethodParameter(0)), + typeof(string), + typeof(int) + })!; /// /// Adds a tag to the collection of tags associated with an EF LINQ query. Tags are query annotations diff --git a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs index d200e005fea..fe8b95eb478 100644 --- a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs +++ b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs @@ -37,7 +37,8 @@ public static class ExpressionExtensions return Expression.Not( Expression.Call( currentValueExpression, - currentValueExpression.Type.GetRequiredMethod("get_HasValue"))); + Check.NotNull( + currentValueExpression.Type.GetMethod("get_HasValue"), $"get_HasValue on {currentValueExpression.Type.Name}"))); } var property = propertyBase as IReadOnlyProperty; diff --git a/src/EFCore/Infrastructure/ExpressionExtensions.cs b/src/EFCore/Infrastructure/ExpressionExtensions.cs index 6043f8d20b3..98be1707106 100644 --- a/src/EFCore/Infrastructure/ExpressionExtensions.cs +++ b/src/EFCore/Infrastructure/ExpressionExtensions.cs @@ -299,7 +299,7 @@ public static IReadOnlyList GetMemberAccessList(this LambdaExpressio /// /// public static readonly MethodInfo ValueBufferTryReadValueMethod - = typeof(ExpressionExtensions).GetRequiredDeclaredMethod(nameof(ValueBufferTryReadValue)); + = typeof(ExpressionExtensions).GetTypeInfo().GetDeclaredMethod(nameof(ValueBufferTryReadValue))!; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static TValue ValueBufferTryReadValue( diff --git a/src/EFCore/Internal/DbSetSource.cs b/src/EFCore/Internal/DbSetSource.cs index d50422da54a..d66eb09291d 100644 --- a/src/EFCore/Internal/DbSetSource.cs +++ b/src/EFCore/Internal/DbSetSource.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Internal; public class DbSetSource : IDbSetSource { private static readonly MethodInfo GenericCreateSet - = typeof(DbSetSource).GetTypeInfo().GetRequiredDeclaredMethod(nameof(CreateSetFactory)); + = typeof(DbSetSource).GetTypeInfo().GetDeclaredMethod(nameof(CreateSetFactory))!; private readonly ConcurrentDictionary<(Type Type, string? Name), Func> _cache = new(); diff --git a/src/EFCore/Internal/EntityFinderSource.cs b/src/EFCore/Internal/EntityFinderSource.cs index e7d45092ba7..b1692e4e6dc 100644 --- a/src/EFCore/Internal/EntityFinderSource.cs +++ b/src/EFCore/Internal/EntityFinderSource.cs @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Internal; public class EntityFinderSource : IEntityFinderSource { private static readonly MethodInfo GenericCreate - = typeof(EntityFinderSource).GetTypeInfo().GetRequiredDeclaredMethod(nameof(CreateConstructor)); + = typeof(EntityFinderSource).GetTypeInfo().GetDeclaredMethod(nameof(CreateConstructor))!; private readonly ConcurrentDictionary> _cache = new(); diff --git a/src/EFCore/Internal/ManyToManyLoaderFactory.cs b/src/EFCore/Internal/ManyToManyLoaderFactory.cs index c325527b57c..05953b2b651 100644 --- a/src/EFCore/Internal/ManyToManyLoaderFactory.cs +++ b/src/EFCore/Internal/ManyToManyLoaderFactory.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Internal; public class ManyToManyLoaderFactory { private static readonly MethodInfo GenericCreate - = typeof(ManyToManyLoaderFactory).GetTypeInfo().GetRequiredDeclaredMethod(nameof(CreateManyToMany)); + = typeof(ManyToManyLoaderFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateManyToMany))!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs index e37c3f0a4ca..37a8334f093 100644 --- a/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs @@ -11,8 +11,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions; /// public class EntityTypeConfigurationEntityTypeAttributeConvention : EntityTypeAttributeConventionBase { - private static readonly MethodInfo ConfigureMethod = typeof(EntityTypeConfigurationEntityTypeAttributeConvention) - .GetRequiredDeclaredMethod(nameof(Configure)); + private static readonly MethodInfo ConfigureMethod + = typeof(EntityTypeConfigurationEntityTypeAttributeConvention).GetTypeInfo().GetDeclaredMethod(nameof(Configure))!; /// /// Creates a new instance of . diff --git a/src/EFCore/Metadata/Internal/PropertyBase.cs b/src/EFCore/Metadata/Internal/PropertyBase.cs index d70a8a220f1..0a604920be5 100644 --- a/src/EFCore/Metadata/Internal/PropertyBase.cs +++ b/src/EFCore/Metadata/Internal/PropertyBase.cs @@ -411,7 +411,7 @@ public virtual IComparer CurrentValueComparer }); private static readonly MethodInfo ContainsKeyMethod = - typeof(IDictionary).GetRequiredMethod(nameof(IDictionary.ContainsKey), typeof(string)); + typeof(IDictionary).GetMethod(nameof(IDictionary.ContainsKey), new[] { typeof(string) })!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Query/EntityShaperExpression.cs b/src/EFCore/Query/EntityShaperExpression.cs index c3f0c3910b8..a6bf2d66416 100644 --- a/src/EFCore/Query/EntityShaperExpression.cs +++ b/src/EFCore/Query/EntityShaperExpression.cs @@ -21,7 +21,7 @@ namespace Microsoft.EntityFrameworkCore.Query; public class EntityShaperExpression : Expression, IPrintableExpression { private static readonly MethodInfo CreateUnableToDiscriminateExceptionMethod - = typeof(EntityShaperExpression).GetRequiredDeclaredMethod(nameof(CreateUnableToDiscriminateException)); + = typeof(EntityShaperExpression).GetTypeInfo().GetDeclaredMethod(nameof(CreateUnableToDiscriminateException))!; [UsedImplicitly] private static Exception CreateUnableToDiscriminateException(IEntityType entityType, object discriminator) diff --git a/src/EFCore/Query/EvaluatableExpressionFilter.cs b/src/EFCore/Query/EvaluatableExpressionFilter.cs index eb2731b5889..0ebacc36520 100644 --- a/src/EFCore/Query/EvaluatableExpressionFilter.cs +++ b/src/EFCore/Query/EvaluatableExpressionFilter.cs @@ -23,22 +23,22 @@ public class EvaluatableExpressionFilter : IEvaluatableExpressionFilter // Hence we don't evaluate them. See issue#2069 private static readonly PropertyInfo DateTimeNow - = typeof(DateTime).GetRequiredDeclaredProperty(nameof(DateTime.Now)); + = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.Now))!; private static readonly PropertyInfo DateTimeUtcNow - = typeof(DateTime).GetRequiredDeclaredProperty(nameof(DateTime.UtcNow)); + = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.UtcNow))!; private static readonly PropertyInfo DateTimeToday - = typeof(DateTime).GetRequiredDeclaredProperty(nameof(DateTime.Today)); + = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.Today))!; private static readonly PropertyInfo DateTimeOffsetNow - = typeof(DateTimeOffset).GetRequiredDeclaredProperty(nameof(DateTimeOffset.Now)); + = typeof(DateTimeOffset).GetTypeInfo().GetDeclaredProperty(nameof(DateTimeOffset.Now))!; private static readonly PropertyInfo DateTimeOffsetUtcNow - = typeof(DateTimeOffset).GetRequiredDeclaredProperty(nameof(DateTimeOffset.UtcNow)); + = typeof(DateTimeOffset).GetTypeInfo().GetDeclaredProperty(nameof(DateTimeOffset.UtcNow))!; private static readonly MethodInfo GuidNewGuid - = typeof(Guid).GetRequiredDeclaredMethod(nameof(Guid.NewGuid)); + = typeof(Guid).GetTypeInfo().GetDeclaredMethod(nameof(Guid.NewGuid))!; private static readonly MethodInfo RandomNextNoArgs = typeof(Random).GetRuntimeMethod(nameof(Random.Next), Type.EmptyTypes)!; diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs index 67c18613cff..db4a1fca558 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs @@ -430,8 +430,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp var resultSelectorInnerParameter = Expression.Parameter(innerSource.SourceElementType, "i"); var resultType = TransparentIdentifierFactory.Create(_source.SourceElementType, innerSource.SourceElementType); - var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner")!; var resultSelector = Expression.Lambda( Expression.New( @@ -487,7 +487,7 @@ private static Expression AddConvertToObject(Expression expression) private sealed class IncludeExpandingExpressionVisitor : ExpandingExpressionVisitor { private static readonly MethodInfo FetchJoinEntityMethodInfo = - typeof(IncludeExpandingExpressionVisitor).GetRequiredDeclaredMethod(nameof(FetchJoinEntity)); + typeof(IncludeExpandingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(FetchJoinEntity))!; private readonly bool _queryStateManager; private readonly bool _ignoreAutoIncludes; @@ -821,8 +821,8 @@ private Expression ExpandIncludesHelper(Expression root, EntityReference entityR { var resultType = TransparentIdentifierFactory.Create(joinParameter.Type, targetParameter.Type); - var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner")!; var newResultSelector = Expression.Quote( Expression.Lambda( @@ -1135,9 +1135,9 @@ private sealed class GroupingElementReplacingExpressionVisitor : ExpressionVisit _navigationExpansionExpression = (NavigationExpansionExpression)groupByNavigationExpansionExpression.GroupingEnumerable; _keyAccessExpression = Expression.MakeMemberAccess( groupByNavigationExpansionExpression.CurrentParameter, - groupByNavigationExpansionExpression.CurrentParameter.Type.GetRequiredDeclaredProperty( - nameof(IGrouping.Key))); - _keyMemberInfo = parameterExpression.Type.GetRequiredDeclaredProperty(nameof(IGrouping.Key)); + groupByNavigationExpansionExpression.CurrentParameter.Type.GetTypeInfo().GetDeclaredProperty( + nameof(IGrouping.Key))!); + _keyMemberInfo = parameterExpression.Type.GetTypeInfo().GetDeclaredProperty(nameof(IGrouping.Key))!; _cloningExpressionVisitor = new CloningExpressionVisitor(); } diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs index 9e552d4c07b..7894cc19e0e 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public partial class NavigationExpandingExpressionVisitor : ExpressionVisitor { private static readonly PropertyInfo QueryContextContextPropertyInfo - = typeof(QueryContext).GetRequiredDeclaredProperty(nameof(QueryContext.Context)); + = typeof(QueryContext).GetTypeInfo().GetDeclaredProperty(nameof(QueryContext.Context))!; private static readonly Dictionary PredicateLessMethodInfo = new() { @@ -1135,8 +1135,8 @@ static Expression FormatFilter(Expression expression) var transparentIdentifierType = TransparentIdentifierFactory.Create( outerSource.SourceElementType, innerSource.SourceElementType); - var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var newResultSelector = Expression.Lambda( Expression.New( @@ -1184,8 +1184,8 @@ static Expression FormatFilter(Expression expression) var transparentIdentifierType = TransparentIdentifierFactory.Create( outerSource.SourceElementType, innerSource.SourceElementType); - var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var newResultSelector = Expression.Lambda( Expression.New( @@ -1295,8 +1295,8 @@ private static NavigationExpansionExpression ProcessSelect(NavigationExpansionEx var transparentIdentifierType = TransparentIdentifierFactory.Create( source.SourceElementType, collectionElementType); - var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var collectionElementParameter = Expression.Parameter(collectionElementType, "c"); var newResultSelector = Expression.Lambda( diff --git a/src/EFCore/Query/QueryCompilationContext.cs b/src/EFCore/Query/QueryCompilationContext.cs index 85890b004ae..762bdbd2dfb 100644 --- a/src/EFCore/Query/QueryCompilationContext.cs +++ b/src/EFCore/Query/QueryCompilationContext.cs @@ -219,7 +219,7 @@ private Expression InsertRuntimeParameters(Expression query) .Append(query)); private static readonly MethodInfo QueryContextAddParameterMethodInfo - = typeof(QueryContext).GetRequiredDeclaredMethod(nameof(QueryContext.AddParameter)); + = typeof(QueryContext).GetTypeInfo().GetDeclaredMethod(nameof(QueryContext.AddParameter))!; private sealed class NotTranslatedExpressionType : Expression { diff --git a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs index f1e17838c45..9ab1f5d35d1 100644 --- a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query; public abstract class ShapedQueryCompilingExpressionVisitor : ExpressionVisitor { private static readonly PropertyInfo CancellationTokenMemberInfo - = typeof(QueryContext).GetRequiredProperty(nameof(QueryContext.CancellationToken)); + = typeof(QueryContext).GetTypeInfo().GetProperty(nameof(QueryContext.CancellationToken))!; private readonly Expression _cancellationTokenParameter; private readonly EntityMaterializerInjectingExpressionVisitor _entityMaterializerInjectingExpressionVisitor; @@ -278,25 +278,25 @@ private sealed class EntityMaterializerInjectingExpressionVisitor : ExpressionVi = typeof(ValueBuffer).GetTypeInfo().DeclaredConstructors.Single(ci => ci.GetParameters().Length == 1); private static readonly PropertyInfo DbContextMemberInfo - = typeof(QueryContext).GetRequiredProperty(nameof(QueryContext.Context)); + = typeof(QueryContext).GetTypeInfo().GetProperty(nameof(QueryContext.Context))!; private static readonly PropertyInfo EntityMemberInfo - = typeof(InternalEntityEntry).GetRequiredProperty(nameof(InternalEntityEntry.Entity)); + = typeof(InternalEntityEntry).GetTypeInfo().GetProperty(nameof(InternalEntityEntry.Entity))!; private static readonly PropertyInfo EntityTypeMemberInfo - = typeof(InternalEntityEntry).GetRequiredProperty(nameof(InternalEntityEntry.EntityType)); + = typeof(InternalEntityEntry).GetTypeInfo().GetProperty(nameof(InternalEntityEntry.EntityType))!; private static readonly MethodInfo TryGetEntryMethodInfo = typeof(QueryContext).GetTypeInfo().GetDeclaredMethods(nameof(QueryContext.TryGetEntry)) .Single(mi => mi.GetParameters().Length == 4); private static readonly MethodInfo StartTrackingMethodInfo - = typeof(QueryContext).GetRequiredMethod( - nameof(QueryContext.StartTracking), typeof(IEntityType), typeof(object), typeof(ValueBuffer)); + = typeof(QueryContext).GetMethod( + nameof(QueryContext.StartTracking), new[] { typeof(IEntityType), typeof(object), typeof(ValueBuffer) })!; private static readonly MethodInfo CreateNullKeyValueInNoTrackingQueryMethod - = typeof(EntityMaterializerInjectingExpressionVisitor).GetRequiredDeclaredMethod( - nameof(CreateNullKeyValueInNoTrackingQuery)); + = typeof(EntityMaterializerInjectingExpressionVisitor) + .GetTypeInfo().GetDeclaredMethod(nameof(CreateNullKeyValueInNoTrackingQuery))!; private readonly IEntityMaterializerSource _entityMaterializerSource; private readonly QueryTrackingBehavior _queryTrackingBehavior; diff --git a/src/Shared/SharedTypeExtensions.cs b/src/Shared/SharedTypeExtensions.cs index a6af6ee48cd..50778d10f3f 100644 --- a/src/Shared/SharedTypeExtensions.cs +++ b/src/Shared/SharedTypeExtensions.cs @@ -117,47 +117,6 @@ public static bool IsAnonymousType(this Type type) return props.SingleOrDefault(); } - public static MethodInfo GetRequiredMethod(this Type type, string name, params Type[] parameters) - { - var method = type.GetTypeInfo().GetMethod(name, parameters); - - if (method == null - && parameters.Length == 0) - { - method = type.GetMethod(name); - } - - if (method == null) - { - throw new InvalidOperationException(); - } - - return method; - } - - public static PropertyInfo GetRequiredProperty(this Type type, string name) - => type.GetTypeInfo().GetProperty(name) - ?? throw new InvalidOperationException($"Could not find property '{name}' on type '{type}'"); - - public static FieldInfo GetRequiredDeclaredField(this Type type, string name) - => type.GetTypeInfo().GetDeclaredField(name) - ?? throw new InvalidOperationException($"Could not find field '{name}' on type '{type}'"); - - public static MethodInfo GetRequiredDeclaredMethod(this Type type, string name) - => type.GetTypeInfo().GetDeclaredMethod(name) - ?? throw new InvalidOperationException($"Could not find method '{name}' on type '{type}'"); - - public static MethodInfo GetRequiredDeclaredMethod(this Type type, string name, Func methodSelector) - => type.GetTypeInfo().GetDeclaredMethods(name).Single(methodSelector); - - public static PropertyInfo GetRequiredDeclaredProperty(this Type type, string name) - => type.GetTypeInfo().GetDeclaredProperty(name) - ?? throw new InvalidOperationException($"Could not find property '{name}' on type '{type}'"); - - public static PropertyInfo GetRequiredRuntimeProperty(this Type type, string name) - => type.GetTypeInfo().GetRuntimeProperty(name) - ?? throw new InvalidOperationException($"Could not find property '{name}' on type '{type}'"); - public static bool IsInstantiable(this Type type) => !type.IsAbstract && !type.IsInterface