GW2.NET icon indicating copy to clipboard operation
GW2.NET copied to clipboard

Add 'CanConvert'

Open SamHurne opened this issue 8 years ago • 0 comments

[Moved from Codeplex: https://gw2dotnet.codeplex.com/workitem/1347]

The IConverter classes currently do not provide fail-safe conversion behavior.

I don't think it is desirable to add fail-safe overloads à la bool TryConvert(..., out result)

Instead, add a method that determines whether the current converter can convert a given value.

interface IConverter<in TInput, out TOutput>
{
    bool CanConvert(TInput value, object state);
    TOutput Convert(Tinput value, object state);
}

With this in place, try-catch blocks are no longer needed.

if (converter.CanConvert(value, null)
{
    var convertedValue = converter.Convert(value, null);
}

Up for grabs

SamHurne avatar Sep 19 '15 15:09 SamHurne