Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'CanConvert' #4

Open
SamHurne opened this issue Sep 19, 2015 · 0 comments
Open

Add 'CanConvert' #4

SamHurne opened this issue Sep 19, 2015 · 0 comments

Comments

@SamHurne
Copy link
Collaborator

[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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant