diff --git a/Dependencies.targets b/Dependencies.targets index 50ef13b..9e5e4b4 100644 --- a/Dependencies.targets +++ b/Dependencies.targets @@ -1,34 +1,34 @@ - 5.0.6 - [$(DotnetRuntimeVersion), 6.0.0) + 6.0.0 + [$(DotnetRuntimeVersion), 7.0.0) - - - + + + - + - + - - - + + + - - + + @@ -37,8 +37,8 @@ - - + + @@ -60,7 +60,7 @@ - + @@ -82,7 +82,7 @@ - + diff --git a/Directory.Build.props b/Directory.Build.props index fc62e57..a613734 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -23,9 +23,9 @@ - net5.0 - net5.0-windows - netcoreapp5.0 + net6.0 + net6.0-windows + netcoreapp6.0 netstandard2.1 diff --git a/Version.props b/Version.props index 57f0525..babb42d 100644 --- a/Version.props +++ b/Version.props @@ -8,7 +8,7 @@ - "rtm" - "servicing" --> - 5.0.0 + 6.0.0 alpha 1 diff --git a/global.json b/global.json index 9c63469..2a8dd78 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "5.0.203", + "version": "6.0.100", "allowPrerelease": false, "rollForward": "latestFeature" } diff --git a/src/EFCore.Jet.Data/EFCore.Jet.Data.csproj b/src/EFCore.Jet.Data/EFCore.Jet.Data.csproj index 98844da..c8a3675 100644 --- a/src/EFCore.Jet.Data/EFCore.Jet.Data.csproj +++ b/src/EFCore.Jet.Data/EFCore.Jet.Data.csproj @@ -2,7 +2,7 @@ Jet/ACE data provider for .NET used by EntityFramworkCore.Jet (Microsoft Access MDB/ACCDB files). - $(DefaultNetStandardTargetFramework) + net6.0-windows AnyCPU;x86;x64 EntityFrameworkCore.Jet.Data EntityFrameworkCore.Jet.Data diff --git a/src/EFCore.Jet.Odbc/EFCore.Jet.Odbc.csproj b/src/EFCore.Jet.Odbc/EFCore.Jet.Odbc.csproj index 41e5a8d..cb21eab 100644 --- a/src/EFCore.Jet.Odbc/EFCore.Jet.Odbc.csproj +++ b/src/EFCore.Jet.Odbc/EFCore.Jet.Odbc.csproj @@ -2,7 +2,7 @@ Explicit ODBC support for Jet/ACE database provider for Entity Framework Core (Microsoft Access MDB/ACCDB files). - $(WindowsOnlyNetCoreTargetFramework) + net6.0-windows EntityFrameworkCore.Jet.Odbc EntityFrameworkCore.Jet $(PackageTags);ODBC;System.Data.Odbc diff --git a/src/EFCore.Jet.OleDb/EFCore.Jet.OleDb.csproj b/src/EFCore.Jet.OleDb/EFCore.Jet.OleDb.csproj index 0ff0e6c..ce7e1e5 100644 --- a/src/EFCore.Jet.OleDb/EFCore.Jet.OleDb.csproj +++ b/src/EFCore.Jet.OleDb/EFCore.Jet.OleDb.csproj @@ -2,7 +2,7 @@ Explicit OLE DB support for Jet/ACE database provider for Entity Framework Core (Microsoft Access MDB/ACCDB files). - $(WindowsOnlyNetCoreTargetFramework) + net6.0-windows EntityFrameworkCore.Jet.OleDb EntityFrameworkCore.Jet $(PackageTags);OLE DB;OLEDB;System.Data.OleDb diff --git a/src/EFCore.Jet/EFCore.Jet.csproj b/src/EFCore.Jet/EFCore.Jet.csproj index 3a60dcf..53baaaa 100644 --- a/src/EFCore.Jet/EFCore.Jet.csproj +++ b/src/EFCore.Jet/EFCore.Jet.csproj @@ -2,7 +2,7 @@ Jet/ACE database provider for Entity Framework Core (Microsoft Access MDB/ACCDB files). - $(DefaultNetStandardTargetFramework) + net6.0-windows EntityFrameworkCore.Jet EntityFrameworkCore.Jet AnyCPU;x86;x64 diff --git a/src/EFCore.Jet/Extensions/JetModelExtensions.cs b/src/EFCore.Jet/Extensions/JetModelExtensions.cs index 95b6ba7..8ed3d15 100644 --- a/src/EFCore.Jet/Extensions/JetModelExtensions.cs +++ b/src/EFCore.Jet/Extensions/JetModelExtensions.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore /// /// The model. /// The default identity seed. - public static int GetIdentitySeed([NotNull] this IModel model) + public static int GetIdentitySeed([NotNull] this IReadOnlyModel model) => (int?) model[JetAnnotationNames.IdentitySeed] ?? 1; /// @@ -53,7 +53,7 @@ namespace Microsoft.EntityFrameworkCore /// /// The model. /// The default identity increment. - public static int GetIdentityIncrement([NotNull] this IModel model) + public static int GetIdentityIncrement([NotNull] this IReadOnlyModel model) => (int?) model[JetAnnotationNames.IdentityIncrement] ?? 1; /// @@ -93,7 +93,7 @@ namespace Microsoft.EntityFrameworkCore /// /// The model. /// The default . - public static JetValueGenerationStrategy? GetValueGenerationStrategy([NotNull] this IModel model) + public static JetValueGenerationStrategy? GetValueGenerationStrategy([NotNull] this IReadOnlyModel model) => (JetValueGenerationStrategy?) model[JetAnnotationNames.ValueGenerationStrategy]; /// diff --git a/src/EFCore.Jet/Extensions/JetPropertyExtensions.cs b/src/EFCore.Jet/Extensions/JetPropertyExtensions.cs index 609f6ea..b013077 100644 --- a/src/EFCore.Jet/Extensions/JetPropertyExtensions.cs +++ b/src/EFCore.Jet/Extensions/JetPropertyExtensions.cs @@ -22,7 +22,7 @@ namespace Microsoft.EntityFrameworkCore /// /// The property. /// The identity seed. - public static int? GetIdentitySeed([NotNull] this IProperty property) + public static int? GetIdentitySeed([NotNull] this IReadOnlyProperty property) => (int?)property[JetAnnotationNames.IdentitySeed]; /// @@ -31,7 +31,7 @@ namespace Microsoft.EntityFrameworkCore /// The property. /// The identifier of the store object. /// The identity seed. - public static int? GetIdentitySeed([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static int? GetIdentitySeed([NotNull] this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(JetAnnotationNames.IdentitySeed); if (annotation != null) @@ -88,7 +88,7 @@ namespace Microsoft.EntityFrameworkCore /// /// The property. /// The identity increment. - public static int? GetIdentityIncrement([NotNull] this IProperty property) + public static int? GetIdentityIncrement([NotNull] this IReadOnlyProperty property) => (int?)property[JetAnnotationNames.IdentityIncrement]; /// @@ -97,7 +97,7 @@ namespace Microsoft.EntityFrameworkCore /// The property. /// The identifier of the store object. /// The identity increment. - public static int? GetIdentityIncrement([NotNull] this IProperty property, in StoreObjectIdentifier storeObject) + public static int? GetIdentityIncrement([NotNull] this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(JetAnnotationNames.IdentityIncrement); if (annotation != null) @@ -159,7 +159,7 @@ namespace Microsoft.EntityFrameworkCore /// /// The property. /// The strategy, or if none was set. - public static JetValueGenerationStrategy GetValueGenerationStrategy([NotNull] this IProperty property) + public static JetValueGenerationStrategy GetValueGenerationStrategy([NotNull] this IReadOnlyProperty property) { var annotation = property.FindAnnotation(JetAnnotationNames.ValueGenerationStrategy); if (annotation != null) @@ -190,7 +190,7 @@ namespace Microsoft.EntityFrameworkCore /// The identifier of the store object. /// The strategy, or if none was set. public static JetValueGenerationStrategy GetValueGenerationStrategy( - [NotNull] this IProperty property, + [NotNull] this IReadOnlyProperty property, in StoreObjectIdentifier storeObject) { var annotation = property.FindAnnotation(JetAnnotationNames.ValueGenerationStrategy); @@ -220,7 +220,7 @@ namespace Microsoft.EntityFrameworkCore return GetDefaultValueGenerationStrategy(property); } - private static JetValueGenerationStrategy GetDefaultValueGenerationStrategy(IProperty property) + private static JetValueGenerationStrategy GetDefaultValueGenerationStrategy(IReadOnlyProperty property) { var modelStrategy = property.DeclaringEntityType.Model.GetValueGenerationStrategy(); @@ -262,7 +262,7 @@ namespace Microsoft.EntityFrameworkCore return value; } - private static void CheckValueGenerationStrategy(IProperty property, JetValueGenerationStrategy? value) + private static void CheckValueGenerationStrategy(IReadOnlyProperty property, JetValueGenerationStrategy? value) { if (value != null) { @@ -292,7 +292,7 @@ namespace Microsoft.EntityFrameworkCore /// /// The property. /// true if compatible. - public static bool IsCompatibleWithValueGeneration([NotNull] IProperty property) + public static bool IsCompatibleWithValueGeneration([NotNull] IReadOnlyProperty property) { var type = property.ClrType; diff --git a/src/EFCore.Jet/Infrastructure/Internal/JetOptionsExtension.cs b/src/EFCore.Jet/Infrastructure/Internal/JetOptionsExtension.cs index e7a30f0..9cd4a1f 100644 --- a/src/EFCore.Jet/Infrastructure/Internal/JetOptionsExtension.cs +++ b/src/EFCore.Jet/Infrastructure/Internal/JetOptionsExtension.cs @@ -175,7 +175,7 @@ namespace EntityFrameworkCore.Jet.Infrastructure.Internal private sealed class ExtensionInfo : RelationalExtensionInfo { - private long? _serviceProviderHash; + private int? _serviceProviderHash; private string _logFragment; public ExtensionInfo(IDbContextOptionsExtension extension) @@ -227,12 +227,12 @@ namespace EntityFrameworkCore.Jet.Infrastructure.Internal } } - public override long GetServiceProviderHashCode() + public override int GetServiceProviderHashCode() { if (_serviceProviderHash == null) { _serviceProviderHash = (base.GetServiceProviderHashCode() * 397) ^ - (Extension._dataAccessProviderFactory?.GetHashCode() ?? 0L) ^ + (Extension._dataAccessProviderFactory?.GetHashCode() ?? 0) ^ (Extension._useOuterSelectSkipEmulationViaDataReader.GetHashCode() * 397) ^ (Extension._enableMillisecondsSupport.GetHashCode() * 397)/* ^ (Extension._rowNumberPaging?.GetHashCode() ?? 0L)*/; diff --git a/src/EFCore.Jet/Internal/JetModelValidator.cs b/src/EFCore.Jet/Internal/JetModelValidator.cs index 2d32691..9fa5ec0 100644 --- a/src/EFCore.Jet/Internal/JetModelValidator.cs +++ b/src/EFCore.Jet/Internal/JetModelValidator.cs @@ -91,12 +91,12 @@ namespace EntityFrameworkCore.Jet.Internal && (ConfigurationSource.Convention.Overrides(property.GetPrecisionConfigurationSource()) || ConfigurationSource.Convention.Overrides(property.GetScaleConfigurationSource()))) { - logger.DecimalTypeDefaultWarning(property); + logger.DecimalTypeDefaultWarning((IProperty)property); } if (property.IsKey()) { - logger.DecimalTypeKeyWarning(property); + logger.DecimalTypeKeyWarning((IProperty)property); } } } diff --git a/src/EFCore.Jet/Metadata/Conventions/JetValueGenerationStrategyConvention.cs b/src/EFCore.Jet/Metadata/Conventions/JetValueGenerationStrategyConvention.cs index 0c9a9bb..7866fe4 100644 --- a/src/EFCore.Jet/Metadata/Conventions/JetValueGenerationStrategyConvention.cs +++ b/src/EFCore.Jet/Metadata/Conventions/JetValueGenerationStrategyConvention.cs @@ -82,7 +82,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions } } - static bool IsStrategyNoneNeeded(IProperty property, StoreObjectIdentifier storeObject) + static bool IsStrategyNoneNeeded(IReadOnlyProperty property, StoreObjectIdentifier storeObject) { if (property.ValueGenerated == ValueGenerated.OnAdd && property.GetDefaultValue(storeObject) == null diff --git a/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs b/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs index 9d793e8..995e28e 100644 --- a/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs +++ b/src/EFCore.Jet/Metadata/Conventions/JetValueGeneratorConvention.cs @@ -75,7 +75,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions /// The property. /// The identifier of the store object. /// The store value generation strategy to set for the given property. - public static new ValueGenerated? GetValueGenerated([NotNull] IProperty property, in StoreObjectIdentifier storeObject) + public static ValueGenerated? GetValueGenerated([NotNull] IProperty property, in StoreObjectIdentifier storeObject) => RelationalValueGenerationConvention.GetValueGenerated(property, storeObject) ?? (property.GetValueGenerationStrategy(storeObject) != JetValueGenerationStrategy.None ? ValueGenerated.OnAdd diff --git a/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs b/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs index 75f0db8..4f29e70 100644 --- a/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs +++ b/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs @@ -37,7 +37,6 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal private readonly ITypeMappingSource _typeMappingSource; private readonly IJetOptions _options; - private readonly JetSqlExpressionFactory _sqlExpressionFactory; private readonly ISqlGenerationHelper _sqlGenerationHelper; private CoreTypeMapping _boolTypeMapping; @@ -47,12 +46,10 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal /// public JetQuerySqlGenerator( [NotNull] QuerySqlGeneratorDependencies dependencies, - ISqlExpressionFactory sqlExpressionFactory, ITypeMappingSource typeMappingSource, IJetOptions options) : base(dependencies) { - _sqlExpressionFactory = (JetSqlExpressionFactory) sqlExpressionFactory; _typeMappingSource = typeMappingSource; _options = options; _sqlGenerationHelper = dependencies.SqlGenerationHelper; @@ -250,11 +247,12 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal return base.VisitOrdering(orderingExpression); } + protected override Expression VisitSqlBinary(SqlBinaryExpression sqlBinaryExpression) { Check.NotNull(sqlBinaryExpression, nameof(sqlBinaryExpression)); - if (sqlBinaryExpression.OperatorType == ExpressionType.Coalesce) + /*if (sqlBinaryExpression.OperatorType == ExpressionType.Coalesce) { Visit( _sqlExpressionFactory.Case( @@ -266,7 +264,7 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal }, sqlBinaryExpression.Left)); return sqlBinaryExpression; - } + }*/ return base.VisitSqlBinary(sqlBinaryExpression); } @@ -288,7 +286,7 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal // of the returned value using a different (unaligned) type mapping (e.g. date/time related ones). if (_convertMappings.TryGetValue(convertExpression.Type.Name, out var function)) { - Visit( + /*Visit( _sqlExpressionFactory.NullChecked( convertExpression.Operand, _sqlExpressionFactory.Function( @@ -297,7 +295,7 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal false, new[] {false}, typeMapping.ClrType))); - + */ return convertExpression; } @@ -322,11 +320,7 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal protected override Expression VisitLike(LikeExpression likeExpression) { Check.NotNull(likeExpression, nameof(likeExpression)); - - if (likeExpression.EscapeChar != null) - base.VisitLike(_sqlExpressionFactory.Like(likeExpression.Match, likeExpression.Pattern)); - else - base.VisitLike(likeExpression); + base.VisitLike(likeExpression); return likeExpression; } @@ -447,5 +441,7 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal protected override Expression VisitRowNumber(RowNumberExpression rowNumberExpression) => throw new InvalidOperationException(CoreStrings.TranslationFailed(rowNumberExpression)); + + } } \ No newline at end of file diff --git a/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGeneratorFactory.cs b/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGeneratorFactory.cs index 72325ba..e6178f9 100644 --- a/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGeneratorFactory.cs +++ b/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGeneratorFactory.cs @@ -14,7 +14,6 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal public class JetQuerySqlGeneratorFactory : IQuerySqlGeneratorFactory { [NotNull] private readonly QuerySqlGeneratorDependencies _dependencies; - [NotNull] private readonly JetSqlExpressionFactory _sqlExpressionFactory; [NotNull] private readonly ITypeMappingSource _typeMappingSource; [NotNull] private readonly IJetOptions _options; @@ -24,17 +23,15 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal /// public JetQuerySqlGeneratorFactory( [NotNull] QuerySqlGeneratorDependencies dependencies, - [NotNull] ISqlExpressionFactory sqlExpressionFactory, [NotNull] ITypeMappingSource typeMappingSource, [NotNull] IJetOptions options) { _dependencies = dependencies; - _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory; _typeMappingSource = typeMappingSource; _options = options; } public virtual QuerySqlGenerator Create() - => new JetQuerySqlGenerator(_dependencies, _sqlExpressionFactory, _typeMappingSource, _options); + => new JetQuerySqlGenerator(_dependencies, _typeMappingSource, _options); } } diff --git a/src/EFCore.Jet/Scaffolding/Internal/JetCodeGenerator.cs b/src/EFCore.Jet/Scaffolding/Internal/JetCodeGenerator.cs index 783c9a7..b0a3033 100644 --- a/src/EFCore.Jet/Scaffolding/Internal/JetCodeGenerator.cs +++ b/src/EFCore.Jet/Scaffolding/Internal/JetCodeGenerator.cs @@ -1,5 +1,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Reflection; +using EntityFrameworkCore.Jet.Infrastructure; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; @@ -15,6 +18,12 @@ namespace EntityFrameworkCore.Jet.Scaffolding.Internal /// public class JetCodeGenerator : ProviderCodeGenerator { + private static readonly MethodInfo _useJetMethodInfo + = typeof(JetDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod( + nameof(JetDbContextOptionsBuilderExtensions.UseJet), + typeof(DbContextOptionsBuilder), + typeof(string), + typeof(Action)); /// /// Initializes a new instance of the class. /// @@ -33,8 +42,7 @@ namespace EntityFrameworkCore.Jet.Scaffolding.Internal public override MethodCallCodeFragment GenerateUseProvider( string connectionString, MethodCallCodeFragment providerOptions) - => new MethodCallCodeFragment( - nameof(JetDbContextOptionsBuilderExtensions.UseJet), + => new(_useJetMethodInfo, providerOptions == null ? new object[] { connectionString } : new object[] { connectionString, new NestedClosureCodeFragment("x", providerOptions) }); diff --git a/src/EFCore.Jet/Storage/Internal/JetDatabaseCreator.cs b/src/EFCore.Jet/Storage/Internal/JetDatabaseCreator.cs index f5bd621..44a4f0f 100644 --- a/src/EFCore.Jet/Storage/Internal/JetDatabaseCreator.cs +++ b/src/EFCore.Jet/Storage/Internal/JetDatabaseCreator.cs @@ -57,8 +57,7 @@ namespace EntityFrameworkCore.Jet.Storage.Internal /// public override bool HasTables() { - return Dependencies.ExecutionStrategyFactory - .Create() + return Dependencies.ExecutionStrategy .Execute( _relationalConnection, connection => @@ -82,7 +81,7 @@ namespace EntityFrameworkCore.Jet.Storage.Internal /// doing so can result in application failures when updating to a new Entity Framework Core release. /// public override Task HasTablesAsync(CancellationToken cancellationToken = default) - => Dependencies.ExecutionStrategyFactory.Create().ExecuteAsync( + => Dependencies.ExecutionStrategy.ExecuteAsync( _relationalConnection, async (connection, ct) => { diff --git a/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs b/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs index d2af7b2..dd59315 100644 --- a/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs +++ b/src/EFCore.Jet/Storage/Internal/JetRelationalConnection.cs @@ -65,7 +65,7 @@ namespace EntityFrameworkCore.Jet.Storage.Internal .UseJet(connection, b => b.CommandTimeout(CommandTimeout ?? DefaultMasterConnectionCommandTimeout)) .Options; - return new JetRelationalConnection(Dependencies.With(contextOptions)); + return new JetRelationalConnection(Dependencies with { ContextOptions = contextOptions }); } /// diff --git a/src/EFCore.Jet/Update/Internal/JetModificationCommandBatch.cs b/src/EFCore.Jet/Update/Internal/JetModificationCommandBatch.cs index 7e63ed2..0bb7818 100644 --- a/src/EFCore.Jet/Update/Internal/JetModificationCommandBatch.cs +++ b/src/EFCore.Jet/Update/Internal/JetModificationCommandBatch.cs @@ -35,7 +35,7 @@ namespace EntityFrameworkCore.Jet.Update.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override bool CanAddCommand(ModificationCommand modificationCommand) + protected override bool CanAddCommand(IReadOnlyModificationCommand modificationCommand) => ModificationCommands.Count < MaxRowCount; /// diff --git a/src/EFCore.Jet/Update/Internal/JetUpdateSqlGenerator.cs b/src/EFCore.Jet/Update/Internal/JetUpdateSqlGenerator.cs index 2a8c668..bcb1be1 100644 --- a/src/EFCore.Jet/Update/Internal/JetUpdateSqlGenerator.cs +++ b/src/EFCore.Jet/Update/Internal/JetUpdateSqlGenerator.cs @@ -36,7 +36,7 @@ namespace EntityFrameworkCore.Jet.Update.Internal /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - protected override void AppendIdentityWhereCondition(StringBuilder commandStringBuilder, ColumnModification columnModification) + protected override void AppendIdentityWhereCondition(StringBuilder commandStringBuilder, IColumnModification columnModification) { SqlGenerationHelper.DelimitIdentifier(commandStringBuilder, columnModification.ColumnName); commandStringBuilder.Append(" = "); diff --git a/src/Shared/SharedTypeExtensions.cs b/src/Shared/SharedTypeExtensions.cs index 970e41d..00252d9 100644 --- a/src/Shared/SharedTypeExtensions.cs +++ b/src/Shared/SharedTypeExtensions.cs @@ -54,6 +54,51 @@ namespace System 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 MethodInfo GetRequiredRuntimeMethod(this Type type, string name, params Type[] parameters) + => type.GetTypeInfo().GetRuntimeMethod(name, parameters) + ?? throw new InvalidOperationException($"Could not find method '{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) => IsInstantiable(type.GetTypeInfo()); private static bool IsInstantiable(TypeInfo type)