Sad truth - no way to implement operator convertion in abstract class like this:
public abstract class DoubleValueBase
{
protected DoubleValueBase(double value)
{
AssertThatValueIsWithinRange(value);
this.Value = value;
}
public double Value { get; private set; }
public static implicit operator DoubleValueBase(double value)
{
return (DoubleValueBase)Activator.CreateInstance(??);
}
public static explicit operator double(DoubleValueBase value)
{
return value.Value;
}
protected abstract void AssertThatValueIsWithinRange(double value);
}
So it isn't possible to derive Power class from DoubleValueBase and write Power power = 5.3;
unless you create implicit convertion operator in Power class. Now imagine, that you need to have 20 classes derived from DoubleValueBase.
P.S. If anybody have an idea if it is possible to do with languages like Boo or Nemerle give me a call please.