I have a class with is a collection of XPaths. I want to pass the name of the field and want to get the XPath for that field. The problem here is I have to store the passed value in a variable and putting an if condition to check for the corresponding XPath variable as shown below.
As of now, I am using the if condition and I can use switch condition as well but this solution is not feasible as the collection of XPath will grow and it will become unmanageable.
class Program
{
static void Main(string[] args)
{
Console.WriteLine(new Program().IReturnXpath("LastName"));
}
public string IReturnXpath(String nameOfField)
{
if (nameOfField.Equals("Lastname"))
return new XpathCollection().Lastname;
else if (nameOfField.Equals("Firstname"))
return new XpathCollection().Firstname;
else
return "Xpath not found";
}
class XpathCollection
{
public string Lastname = "xpath for lastname";
public string Firstname = "xpath for firstname";
}
}