-
Notifications
You must be signed in to change notification settings - Fork 32
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
Handle custom type converters #197
Comments
(moved from accidental duplicate #232)A warning should not be produced. The analyzer can see that CustomType has using System;
using System.ComponentModel;
using System.Globalization;
using NUnit.Framework;
class C
{
// NUnit1001 The value of the argument at position '0' of type string cannot be assigned to
// the argument 'customType' of type CustomType.
// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
[TestCase("String representation")]
public void M(CustomType customType)
{
}
}
[TypeConverter(typeof(CustomTypeConverter))]
struct CustomType
{
public CustomType(string value)
{
Value = value;
}
public string Value { get; }
private sealed class CustomTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return value is string str
? new CustomType(str)
: base.ConvertFrom(context, culture, value);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(string) || base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
return destinationType == typeof(string)
? value.ToString()
: base.ConvertTo(context, culture, value, destinationType);
}
}
} |
@mikkelbu Can I contribute this one if no one is working on it? |
Sure Joseph, you are most welcome to solve this issue. I'll assign it to you. |
We should be able to handle custom type converters.
Suggestions from Gitter: https://gitter.im/GuOrg/Gu.Roslyn.Asserts?at=5e7935aa2e334e1b7aefffa0
The text was updated successfully, but these errors were encountered: