I don't think that will work since the designer does not really attempt to use implicit (or explicit) conversions. If you look at the call stack you'll see that CodeDom uses serialization/deserialization and eventually uses reflection to set the value. Somewhere in that chain it loses the ability or context to attempt a conversion.
That said I am surprised you were able to set it via the designer. VS 2010 will not even show it in the drop down list. You can manually insert it into the designer.cs file but then when you get back to the designer, you'll get the same exception.
[Edit]
~~~~~~~~~
Yes I guessed correctly. This is indeed the case. You can easily reproduce this in your own code too:
static void Main()
{
Program obj = new Program();
Test test = new Test();
var mi = typeof(Program).GetMethod("set_Number");
mi.Invoke(obj, new object[] { test });
}
public int Number { get; set; }
class Test
{
public static implicit operator int(Test t)
{
return 50;
}
}
Note that instead of using a
PropertyInfo
, I am using a
MethodInfo
- because this is what the Visual Studio designer does too.