I have created a Method shown below,
public BOEod CheckCommandStatus(BOEod pBo, IList<string> pProperties)
{
pBo.isValid = false;
if (pProperties != null)
{
int Num=-1;
pBo.GetType().GetProperty(pProperties[0].ToString()).GetValue(pBo, null);
if (ifIntegerGetValue(pBo.GetType().GetProperty(pProperties[0].ToString()).GetValue(pBo, null).ToString(), out Num))
{
if (Num == 1)
pBo.isValid = true;
}
}
return pBo;
}
I need to convert this method, in such a way that it should accept all Type of Objects(now i am accepting only Objects of type “BOEod”).
As i am newbie to .Net so don no exactly how to use Generics. Can i accomplish this using Generics.?
Solution Something like this:
public T CheckCommandStatus<T>(T pBO, Ilist<string> pProperties){..}
Here Main thing is i need to change the Property of the Passed Object(pBO) and return it.
You would need
BOEodto implement an interface which definesIsValid.You would then add a generic constraint to your method to only accept objects implementing that interface.
….
….