TypeConverterTAcceptsNull Property

Gets a value indicating whether the converter accepts null references as input.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings.TypeConverters
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public abstract bool AcceptsNull { get; }

Property Value

Boolean
true if the converter allows null values as input, otherwise false.

Implements

ITypeConverterTAcceptsNull

Remarks

  Notes to Implementers

This value should be true for all reference types and false for all value types, except NullableT.

Remarks

The behavior is equivalent to the behavior of the AllowNullAttribute: Even if the converters DataType doesn't allow null values, null will be accepted as input if the AcceptsNull property is true.

Example

Writing an own implementation of TypeConverterT is easy:

C#
using FolkerKinzel.CsvTools.Mappings.TypeConverters;
using System.Globalization;

namespace Examples;

/// <summary>
/// Example implementation of <see cref="TypeConverter{T}"/> for the
/// <see cref="Int128"/> struct.
/// </summary>
public sealed class Int128Converter() : TypeConverter<Int128>(true, default)
{
    public override bool AcceptsNull => false;

    public override string? ConvertToString(Int128 value)
        => value.ToString(null, CultureInfo.InvariantCulture);

    public override bool TryParse(ReadOnlySpan<char> value, out Int128 result)
        => Int128.TryParse(value, out result);
}

See Also