Can you add extension methods to a struct?
For future Googlers (and Bingers), here's some code to extend a struct. This example turns the value into a double
type.
public static class ExtensionMethods {
public static double ToDouble(this T value) where T : struct {
return Convert.ToDouble(value);
}
}
After this you can use ToDouble()
like you use ToString()
. Be careful on conversion items like overflows.