Skip to content

Commit

Permalink
Fix nullability annotations for HasType and DerivesFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Aug 4, 2023
1 parent c357ac4 commit 3d3d46d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions ZySharp.Validation/ValidateArgument.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static partial class ValidateArgument
/// <param name="type">The expected type.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> HasType<T>(this IValidatorContext<T> validator, Type type)
public static IValidatorContext<T?> HasType<T>(this IValidatorContext<T?> validator, Type type)
where T : class
{
ValidationInternals.ValidateNotNull(type, nameof(type));
Expand All @@ -39,7 +39,7 @@ public static IValidatorContext<T> HasType<T>(this IValidatorContext<T> validato
/// <param name="types">The allowed types.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> HasType<T>(this IValidatorContext<T> validator, params Type[] types)
public static IValidatorContext<T?> HasType<T>(this IValidatorContext<T?> validator, params Type[] types)
{
ValidationInternals.ValidateNotNull(types, nameof(types));

Expand All @@ -65,7 +65,7 @@ public static IValidatorContext<T> HasType<T>(this IValidatorContext<T> validato
/// <param name="type">The blacklisted type.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> NotHasType<T>(this IValidatorContext<T> validator, Type type)
public static IValidatorContext<T?> NotHasType<T>(this IValidatorContext<T?> validator, Type type)
where T : class
{
ValidationInternals.ValidateNotNull(type, nameof(type));
Expand All @@ -89,7 +89,7 @@ public static IValidatorContext<T> NotHasType<T>(this IValidatorContext<T> valid
/// <param name="types">The blacklisted types.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> NotHasType<T>(this IValidatorContext<T> validator, params Type[] types)
public static IValidatorContext<T?> NotHasType<T>(this IValidatorContext<T?> validator, params Type[] types)
{
ValidationInternals.ValidateNotNull(types, nameof(types));

Expand All @@ -115,7 +115,7 @@ public static IValidatorContext<T> NotHasType<T>(this IValidatorContext<T> valid
/// <param name="type">The parent type.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> DerivesFrom<T>(this IValidatorContext<T> validator, Type type)
public static IValidatorContext<T?> DerivesFrom<T>(this IValidatorContext<T?> validator, Type type)
where T : class
{
ValidationInternals.ValidateNotNull(type, nameof(type));
Expand All @@ -129,7 +129,7 @@ public static IValidatorContext<T> DerivesFrom<T>(this IValidatorContext<T> vali
ValidationInternals.FormatName(validator.Path, null),
type.FullName));
}
});
}, false);
}

/// <summary>
Expand All @@ -140,7 +140,7 @@ public static IValidatorContext<T> DerivesFrom<T>(this IValidatorContext<T> vali
/// <param name="types">The allowed parent types.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> DerivesFrom<T>(this IValidatorContext<T> validator, params Type[] types)
public static IValidatorContext<T?> DerivesFrom<T>(this IValidatorContext<T?> validator, params Type[] types)
{
ValidationInternals.ValidateNotNull(types, nameof(types));

Expand All @@ -155,7 +155,7 @@ public static IValidatorContext<T> DerivesFrom<T>(this IValidatorContext<T> vali
ValidationInternals.FormatName(validator.Path, null),
string.Join(", ", types.Select(x => $"'{x?.FullName ?? "null"}'").ToList())));
}
});
}, false);
}

/// <summary>
Expand All @@ -166,7 +166,7 @@ public static IValidatorContext<T> DerivesFrom<T>(this IValidatorContext<T> vali
/// <param name="type">The blacklisted parent types.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> NotDerivesFrom<T>(this IValidatorContext<T> validator, Type type)
public static IValidatorContext<T?> NotDerivesFrom<T>(this IValidatorContext<T?> validator, Type type)
where T : class
{
ValidationInternals.ValidateNotNull(type, nameof(type));
Expand All @@ -180,7 +180,7 @@ public static IValidatorContext<T> NotDerivesFrom<T>(this IValidatorContext<T> v
ValidationInternals.FormatName(validator.Path, null),
type.FullName));
}
});
}, false);
}

/// <summary>
Expand All @@ -191,7 +191,7 @@ public static IValidatorContext<T> NotDerivesFrom<T>(this IValidatorContext<T> v
/// <param name="types">The blacklisted types.</param>
/// <returns>The unmodified validator context.</returns>
[ExcludeFromCodeCoverage]
public static IValidatorContext<T> NotDerivesFrom<T>(this IValidatorContext<T> validator, params Type[] types)
public static IValidatorContext<T?> NotDerivesFrom<T>(this IValidatorContext<T?> validator, params Type[] types)
{
ValidationInternals.ValidateNotNull(types, nameof(types));

Expand All @@ -206,6 +206,6 @@ public static IValidatorContext<T> NotDerivesFrom<T>(this IValidatorContext<T> v
ValidationInternals.FormatName(validator.Path, null),
string.Join(", ", types.Select(x => $"'{x?.FullName ?? "null"}'").ToList())));
}
});
}, false);
}
}
2 changes: 1 addition & 1 deletion ZySharp.Validation/ValidateArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static partial class ValidateArgument
/// <param name="name">The name of the argument to validate.</param>
/// <param name="action">The action to perform for the selected parameter.</param>
/// <returns>The value of the validated argument.</returns>
[return: NotNullIfNotNull("value")]
[return: NotNullIfNotNull(nameof(value))]
public static T? For<T>([ValidatedNotNull][NoEnumeration] T? value, string name, Action<IValidatorContext<T?>> action)
{
ValidationInternals.ValidateNotNull(name, nameof(name));
Expand Down

0 comments on commit 3d3d46d

Please sign in to comment.