I have a class that pretends to be int, so it overloaded various operators;
public class MyId
{
int value;
public virtual int Value
{
get { return this.value; }
set { this.value = value; }
}
public MyId(int value)
{
this.value = value;
}
public static implicit operator MyId(int rhs)
{
return new MyId(rhs);
}
public static implicit operator int(MyId rhs)
{
return rhs.Value;
}
}
However, when I use code like
PropertyInfo.SetValue(myObj, 13, null)
OR
MyId myId = 13;
int x = Convert.ToInt32(myId);
IConvertible iConvertible = x as IConvertible;
iConvertible.ToType(typeof(MyId), CultureInfo.CurrentCulture);
I get an invalid listing. I am puzzled, both calls seem to be trying to call a conversion to int, which will not be executed, because int does not understand the type of MyId (although there are all assignment operators). Any ideas on a workaround for this, I'm sure I should be missing out on something stupid?
source
share