Update shared files to 3.1.x.

pull/41/head
Lau 6 years ago
parent 0ee60b54b2
commit 9fe1e408c0

@ -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<T>([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<T>(
[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<T> NotEmpty<T>(IReadOnlyList<T> 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;
}
}
}
}

@ -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
}
}
}
Loading…
Cancel
Save