I have the following Method (I exemplify what I need in the comments of the method):
public static Dictionary<int, int> Foo(bool os, bool rad, bool aci, bool outr, string distrito = null)
{
if (os == false && rad == false && aci == false && outr == false)
{
return new Dictionary<int, int>();
}
var parameters = MethodBase.GetCurrentMethod().GetParameters();
foreach (ParameterInfo parameter in parameters)
{
// I would love if parameter.Value existed, because:
// if (parameter.Value==true) {
// x++
// if (x == 1) string s = "true" + parameter.Name;
// if (x > 1) s += "Additional true" + parameter.Name;
// }
// s += "End";
}
return null;
}
I have to know if one or more values of the bool
parameters are true. Since they are four, imagine the combination of if
I would have to do to check if only one is true, or if more than one, which are true.
So, how can I cycle the current value of the incoming Method parameters without using the parameter variable itself?
If you only want to know how many are true, you can turn them into integers and add their values:
If you need the name of the parameters, then you can create an anonymous object and read its properties: