Skip to content

Commit

Permalink
loose ValidatedNotNullAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
6bee committed Dec 14, 2023
1 parent d6dae3a commit 1d57385
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 80 deletions.
64 changes: 20 additions & 44 deletions aqua.tool.Validation/EmbeddedResources/_Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

using ArgumentException = global::System.ArgumentException;
using ArgumentNullException = global::System.ArgumentNullException;
using Attribute = global::System.Attribute;
using AttributeUsageAttribute = global::System.AttributeUsageAttribute;
using AttributeTargets = global::System.AttributeTargets;

using DebuggerNonUserCodeAttribute = global::System.Diagnostics.DebuggerNonUserCodeAttribute;
using DebuggerStepThroughAttribute = global::System.Diagnostics.DebuggerStepThroughAttribute;
Expand All @@ -34,8 +31,6 @@
using EditorBrowsableAttribute = global::System.ComponentModel.EditorBrowsableAttribute;
using EditorBrowsableState = global::System.ComponentModel.EditorBrowsableState;

using ValidatedNotNullAttribute = global::Microsoft.ValidatedNotNullAttribute;

[SuppressMessage(
"Major Bug",
"S3903:Types should be defined in named namespaces",
Expand Down Expand Up @@ -64,7 +59,7 @@ static class _Check
[MethodImpl(AggressiveInlining)]
public static T CheckNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this T? value,
[CallerArgumentExpression("value")] string? name = null)
Expand All @@ -80,7 +75,7 @@ public static T CheckNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static T CheckNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this T? value,
[CallerArgumentExpression("value")] string? name = null)
Expand All @@ -94,7 +89,7 @@ public static T CheckNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static void AssertNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this T? value,
[CallerArgumentExpression("value")] string? name = null)
Expand All @@ -113,7 +108,7 @@ public static void AssertNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static void AssertNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this T? value,
[CallerArgumentExpression("value")] string? name = null)
Expand All @@ -134,7 +129,7 @@ public static void AssertNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static IEnumerable<T> CheckNotNullOrEmpty<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IEnumerable<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand All @@ -161,7 +156,7 @@ public static IEnumerable<T> CheckNotNullOrEmpty<T>(
[MethodImpl(AggressiveInlining)]
public static IReadOnlyCollection<T> CheckNotNullOrEmpty<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IReadOnlyCollection<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand All @@ -188,7 +183,7 @@ public static IReadOnlyCollection<T> CheckNotNullOrEmpty<T>(
[MethodImpl(AggressiveInlining)]
public static IReadOnlyList<T> CheckNotNullOrEmpty<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IReadOnlyList<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand All @@ -215,7 +210,7 @@ public static IReadOnlyList<T> CheckNotNullOrEmpty<T>(
[MethodImpl(AggressiveInlining)]
public static IReadOnlyDictionary<TKey, TValue> CheckNotNullOrEmpty<TKey, TValue>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IReadOnlyDictionary<TKey, TValue>? dict,
[CallerArgumentExpression("dict")] string? name = null)
Expand Down Expand Up @@ -243,7 +238,7 @@ public static IReadOnlyDictionary<TKey, TValue> CheckNotNullOrEmpty<TKey, TValue
[MethodImpl(AggressiveInlining)]
public static IReadOnlySet<T> CheckNotNullOrEmpty<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IReadOnlySet<T>? set,
[CallerArgumentExpression("set")] string? name = null)
Expand Down Expand Up @@ -271,7 +266,7 @@ public static IReadOnlySet<T> CheckNotNullOrEmpty<T>(
[MethodImpl(AggressiveInlining)]
public static string CheckNotNullOrEmpty(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this string? value,
[CallerArgumentExpression("value")] string? name = null)
Expand All @@ -298,7 +293,7 @@ public static string CheckNotNullOrEmpty(
[MethodImpl(AggressiveInlining)]
public static string CheckNotNullOrWhiteSpace(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this string? value,
[CallerArgumentExpression("value")] string? name = null)
Expand All @@ -324,7 +319,7 @@ public static string CheckNotNullOrWhiteSpace(
[MethodImpl(AggressiveInlining)]
public static void AssertNotNullOrEmpty<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IEnumerable<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand All @@ -348,7 +343,7 @@ public static void AssertNotNullOrEmpty<T>(
[MethodImpl(AggressiveInlining)]
public static void AssertNotNullOrWhiteSpace(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this string? value,
[CallerArgumentExpression("value")] string? name = null)
Expand All @@ -373,7 +368,7 @@ public static void AssertNotNullOrWhiteSpace(
[MethodImpl(AggressiveInlining)]
public static IEnumerable<T> CheckItemsNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IEnumerable<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand Down Expand Up @@ -401,7 +396,7 @@ public static IEnumerable<T> CheckItemsNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static IReadOnlyCollection<T> CheckItemsNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IReadOnlyCollection<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand Down Expand Up @@ -429,7 +424,7 @@ public static IReadOnlyCollection<T> CheckItemsNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static IReadOnlyList<T> CheckItemsNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IReadOnlyList<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand Down Expand Up @@ -458,7 +453,7 @@ public static IReadOnlyList<T> CheckItemsNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static IReadOnlySet<T> CheckItemsNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IReadOnlySet<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand Down Expand Up @@ -486,7 +481,7 @@ public static IReadOnlySet<T> CheckItemsNotNull<T>(
[MethodImpl(AggressiveInlining)]
public static void AssertItemsNotNull<T>(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IEnumerable<T>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand All @@ -511,7 +506,7 @@ public static void AssertItemsNotNull<T>(
[MethodImpl((MethodImplOptions)AggressiveInlining)]
public static void AssertItemsNotNullOrEmpty(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IEnumerable<string?>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand All @@ -535,7 +530,7 @@ public static void AssertItemsNotNullOrEmpty(
[MethodImpl((MethodImplOptions)AggressiveInlining)]
public static void AssertItemsNotNullOrWhiteSpace(
#if !NULLABLE_ATTRIBUTES_DISABLE
[NotNull][ValidatedNotNull]
[NotNull]
#endif // NULLABLE_ATTRIBUTES_DISABLE
this IEnumerable<string?>? items,
[CallerArgumentExpression("items")] string? name = null)
Expand All @@ -551,23 +546,4 @@ public static void AssertItemsNotNullOrWhiteSpace(
}
}
}

namespace Microsoft
{
/// <summary>
/// Indicates to Code Analysis that a method validates a particular parameter.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[GeneratedCode("aqua.tool.Validation", "")]
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
#if LOCAL_FILE_TYPES_FEATURE || NET7_0_OR_GREATER
file
#else
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
sealed class ValidatedNotNullAttribute : Attribute
{
}
}
#endif // AQUA_TOOL_VALIDATION_DISABLE
37 changes: 1 addition & 36 deletions aqua.tool.Validation/aqua.tool.Validation.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project InitialTargets="__DetectLanguageFeatures">
<Project>
<PropertyGroup>
<MSBuildAllProjects Condition=" '$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0' ">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
Expand All @@ -16,39 +16,4 @@
Or '$(AquaToolValidationNullableDisable)' == 'yes'
Or '$(AquaToolValidationNullableDisable)' == '1' ">$(DefineConstants);NULLABLE_ATTRIBUTES_DISABLE</DefineConstants>
</PropertyGroup>
<Target Name="__DetectLanguageFeatures" BeforeTargets="Build">
<!--
Try extract specific language version
-->
<__ParseNumber Value="$(LangVersion)">
<Output PropertyName="__LangVersion" TaskParameter="Result" />
</__ParseNumber>
<PropertyGroup>
<!--
Set feature flag for LangVersion >= 11 or `latest`
-->
<LocalFileTypesFeatureEnabled Condition=" '$(LocalFileTypesFeatureEnabled)' == '' And ( '$(LangVersion)' == 'latest' Or '$(__LangVersion)' >= '11' ) ">true</LocalFileTypesFeatureEnabled>
<!--
Define constant based on feature flag
-->
<DefineConstants Condition=" '$(LocalFileTypesFeatureEnabled)' == 'true' ">$(DefineConstants);LOCAL_FILE_TYPES_FEATURE</DefineConstants>
</PropertyGroup>
</Target>
<UsingTask
TaskName="__ParseNumber"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Value ParameterType="System.String" Required="true" />
<Result ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Result = double.TryParse(Value, out double v) ? v.ToString() : "-1";
]]>
</Code>
</Task>
</UsingTask>
</Project>

0 comments on commit 1d57385

Please sign in to comment.