I knew that getting a class from a primitive is not possible, but I would like my class to "look" like a primitive without casting. In this case, my class will work as Decimal:
public interface IFoo
{
static explicit operator Decimal(IFoo tFoo);
}
public class Foo: IFoo
{
private Decimal m_iFooVal;
public Decimal Value
{
get { return m_iFooVal; }
set { m_iFooVal= value; }
}
static explicit operator Decimal(IFoo tFoo)
{
return (tFoo as Foo).Value;
}
}
The above code does not work because an explicit statement cannot be defined in the interface. My code deals with interfaces, and I would like to save it that way. Is it possible to convert IFoo to decimal? Any alternatives are welcome. Example:
IFoo tMyFooInterfaceReference = GetFooSomehow();
Decimal iVal = tMyFooInterfaceReference;
Markp source
share