So I have a c# class with three properties on it.
public class ClassA
{
public bool IsBool1;
public bool IsBool2;
public bool IsBool3;
}
I have a method that does the following.
public void MethodA()
{
ClassA c = GetCurrentClassA();
c.IsBool1 = !c.IsBool1;
ClassADataAccess.Update(c);
this.BindClassADetails(c);
}
Now to keep from writing MethodA over for the other two properties is there a way to write a method that can handle all three?
Something maybe like this?
public void UpdateAndBind(bool value)
{
ClassA c = GetCurrentClassA();
///what to do here to set the property?
ClassADataAccess.Update(c);
this.BindClassADetails();
}
In response to your comment:
There is a way using reflection:
Now…you may want to use try/catch, also perhaps inspect what’s being passed in before using it in various ways to ensure it will not jut blow up…but generally, and most simplistically, that is the way you’d do it.
Good Luck!