diff --git a/src/Shared/Check.cs b/src/Shared/Check.cs index 7727c72..b5c8717 100644 --- a/src/Shared/Check.cs +++ b/src/Shared/Check.cs @@ -4,9 +4,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Reflection; using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore.Internal; +using Microsoft.EntityFrameworkCore.Diagnostics; namespace EntityFrameworkCore.Jet.Utilities { @@ -16,7 +15,9 @@ namespace EntityFrameworkCore.Jet.Utilities [ContractAnnotation("value:null => halt")] public static T NotNull([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName) { +#pragma warning disable IDE0041 // Use 'is null' check if (ReferenceEquals(value, null)) +#pragma warning restore IDE0041 // Use 'is null' check { NotEmpty(parameterName, nameof(parameterName)); @@ -26,23 +27,6 @@ namespace EntityFrameworkCore.Jet.Utilities return value; } - [ContractAnnotation("value:null => halt")] - public static T NotNull( - [NoEnumeration] T value, - [InvokerParameterName] [NotNull] string parameterName, - [NotNull] string propertyName) - { - if (ReferenceEquals(value, null)) - { - NotEmpty(parameterName, nameof(parameterName)); - NotEmpty(propertyName, nameof(propertyName)); - - throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName)); - } - - return value; - } - [ContractAnnotation("value:null => halt")] public static IReadOnlyList NotEmpty(IReadOnlyList value, [InvokerParameterName] [NotNull] string parameterName) { @@ -52,7 +36,7 @@ namespace EntityFrameworkCore.Jet.Utilities { NotEmpty(parameterName, nameof(parameterName)); - throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName)); + throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(parameterName)); } return value; @@ -62,13 +46,13 @@ namespace EntityFrameworkCore.Jet.Utilities public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName) { Exception e = null; - if (ReferenceEquals(value, null)) + if (value is null) { e = new ArgumentNullException(parameterName); } else if (value.Trim().Length == 0) { - e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName)); + e = new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)); } if (e != null) @@ -83,12 +67,12 @@ namespace EntityFrameworkCore.Jet.Utilities public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName) { - if (!ReferenceEquals(value, null) + if (!(value is null) && value.Length == 0) { NotEmpty(parameterName, nameof(parameterName)); - throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName)); + throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)); } return value; @@ -109,16 +93,13 @@ namespace EntityFrameworkCore.Jet.Utilities return value; } - public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull] string parameterName) + [Conditional("DEBUG")] + public static void DebugAssert(bool condition, string message) { - if (!value.GetTypeInfo().IsClass) + if (!condition) { - NotEmpty(parameterName, nameof(parameterName)); - - throw new ArgumentException(CoreStrings.InvalidEntityType(value)); + throw new Exception($"Check.DebugAssert failed: {message}"); } - - return value; } } -} +} \ No newline at end of file diff --git a/src/Shared/CodeAnnotations.cs b/src/Shared/CodeAnnotations.cs index 228a4d0..9865cae 100644 --- a/src/Shared/CodeAnnotations.cs +++ b/src/Shared/CodeAnnotations.cs @@ -5,17 +5,21 @@ using System; namespace JetBrains.Annotations { [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | - AttributeTargets.Property | AttributeTargets.Delegate | - AttributeTargets.Field)] + AttributeTargets.Method + | AttributeTargets.Parameter + | AttributeTargets.Property + | AttributeTargets.Delegate + | AttributeTargets.Field)] internal sealed class NotNullAttribute : Attribute { } [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | - AttributeTargets.Property | AttributeTargets.Delegate | - AttributeTargets.Field)] + AttributeTargets.Method + | AttributeTargets.Parameter + | AttributeTargets.Property + | AttributeTargets.Delegate + | AttributeTargets.Field)] internal sealed class CanBeNullAttribute : Attribute { } @@ -82,9 +86,7 @@ namespace JetBrains.Annotations internal sealed class StringFormatMethodAttribute : Attribute { public StringFormatMethodAttribute([NotNull] string formatParameterName) - { - FormatParameterName = formatParameterName; - } + => FormatParameterName = formatParameterName; [NotNull] public string FormatParameterName { get; } @@ -108,4 +110,4 @@ namespace JetBrains.Annotations Members = 2, WithMembers = Itself | Members } -} +} \ No newline at end of file