GW2.NET
GW2.NET copied to clipboard
Add 'CanConvert'
[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