Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.
This repository was archived by the owner on May 26, 2025. It is now read-only.

Nullable reference types support #30

@adambajguz

Description

@adambajguz

.NET slowly transisions to code that uses nullable reference types. It would be great if Validot supports nullable reference types.

Problem:

public record Model
{
	public string? Language { get; init; }
}

public sealed class ModelValidator : ISpecificationHolder<Model>
{
	public Specification<Model> Specification { get; }

	public ModelValidator()
	{
		Specification = m => m
			.Member(x => x.Language!, language => language // must use a null forgiving operator to use the IsLanguageCode extension 
				.IsLanguageCode()
			);
	}
}

public static IRuleOut<string> IsLanguageCode(this IRuleIn<string> @this) // string doesn't allow a null
{
	// some code
}

I can replace IRuleIn<string> with IRuleIn<string?> but "If the value entering the scope is null, scope commands are not executed." (DOCUMENTATION.md#null-policy) and using null forgiving operator is for me awful.

Nullable support in .NET Standard 2.0

Nullable package can be used to add nullable reference types to .NET Standard and/or a multi-target package can be created (I've never checked how e.g. .NET 6 handles nullable annotations from .NET Standard 2.0 package because I've always used multi-targeted packages so this need verification).

 <PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
    <Nullable>annotations</Nullable>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
    <PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
  </ItemGroup>

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions