Is it possible to get get name of variable that was passed as parameter?
As you asked me to explain why I need this, here is my explain. I'm building a testing framweork using selenium. Here is example where I need that name of variable that was passed as parameter.
I have a page object with field:
[FindsBy(How = How.CssSelector, Using = "input[name='sample']")]
private IWebElement SampleButton { get; set; }
I'm clicking it like:
Click(SampleButton, nameof(SampleButton));
Here is a body of Click function that u see above:
public void Click(IWebElement element, string elementName)
{
element.Click();
Logger.Log("Click: '{0}'", elementName);
}
Result: Button that was passed to function was clicked and in log file I have "Click: SampleButton"
Now I'm looking how to change Click function that it woul be call like:
Click(SampleButton)
It would look like:
public void Click(IWebElement element)
{
element.Click();
Logger.Log("Click: '{0}'", getNameOfVariableThatWasPassedToThisParameter(element));
}
Expected result of getNameOfVariableThatWasPassedToThisParameter(element)
will be string = "SampleButton"
I'm am using things like SendKeys(SampleInput, nameof(SampleInput), valueToSet)
and it set value and log where it was set. So I just want to get rid of that nameof(SampleInput)
. I want to reduce amount of variables than need to be passed to function.