/*I have defined Extension Methods for the TypeX like this*/
public static Int32 GetValueAsInt(this TypeX oValue)
{
return Int32.Parse(oValue.ToString());
}
public static Boolean GetValueAsBoolean(this TypeX oValue)
{
return Boolean.Parse(oValue.ToString());
}
TypeX x = new TypeX("1");
TypeX y = new TypeX("true");
//Method #1
Int32 iXValue = x.GetValueAsInt();
Boolean iYValue = y.GetValueAsBoolean();
//Method #2
Int32 iXValueDirect = Int32.Parse(x.ToString());
Boolean iYValueDirect = Boolean.Parse(y.ToString());
Dont get carried away by TypeX saying that I should define those methods inside TypeX rather than the Extension) I have no control on it (Actual Class I defined it is on SPListItem.
I wanted to convert the TypeX to Int or Boolean and this operation is one Common thing that I am doing in lots of Places in the code. I wanted to know will this cause performance degrade.I tried to interpret IL code using Reflector, but am not good at it. May be for the above example there wont be any performance degrade. In general I wanted to know about the implications with Regard to the Performance while using the Extension methods.
See Question&Answers more detail:os