I have a bunch of properties like this:
>
private Single _Amount;
public Single Amount
{
get { return _Amount; }
set { _Amount = value; }
}
Now I need to change all the Singles to Doubles. So that I don't have
to do this again, how can I define a type
MyAmountType = typeof(Double)
so that I can declare
private MyAmountType _Amount;
public MyAmountType Amount
{
get { return _Amount; }
set { _Amount = value; }
}
?
A technique that I've used with some success is to create a new struct that
wraps the primitive and implicitly convertible to the primitive type. For
example:
public struct MyAmountType: IEquatable<MyAmountType>
{
private double m_Value;
public MyAmountType(double value)
{
m_Value = value;
}
public override bool Equals(object obj)
{
if (obj is MyAmountType)
return Equals((MyAmountType)obj);
return base.Equals(obj);
}
public bool Equals(MyAmountType other)
{
return m_Value.Equals(other.m_Value);
}
public override int GetHashCode()
{
return m_Value.GetHashCode();
}
public override string ToString()
{
return m_Value.ToString();
}
public static implicit operator double(MyAmountType obj)
{
return obj.m_Value;
}
public static implicit operator MyAmountType(double obj)
{
return new MyAmountType(obj);
}
}
That isn't a full implementation but you get the idea.
Best Regards,
Dustin Campbell
Developer Express Inc.