I have a bunch of methods that look like these two:
public void SourceInfo_Get()
{
MethodInfo mi = pFBlock.SourceInfo.GetType().GetMethod("SendGet");
if (mi != null)
{
ParameterInfo[] piArr = mi.GetParameters();
if (piArr.Length == 0)
{
mi.Invoke(pFBlock.SourceInfo, new object[0]);
}
}
}
public void SourceAvailable_Get()
{
MethodInfo mi = pFBlock.SourceAvailable.GetType().GetMethod("SendGet");
if (mi != null)
{
ParameterInfo[] piArr = mi.GetParameters();
if (piArr.Length == 0)
{
mi.Invoke(pFBlock.SourceAvailable, new object[0]);
}
}
}
I have one method for each property in my pFBlock object. with so little changing between methods I feel like there should be a better way to do this, but I can’t think of any.
I’m using VS 2005.
How about 3 methods?
The idea here is to add a helper method that you can pass a parameter into. You can then use the helper method in your other methods to drastically shorten your code.