I have a below code, which I need to call at several places in one of my methods. Instead of copying and pasting all those lines at various places, I would prefer to use a new method, containing below code, which would return the tagElement with correct capability. Any suggestion how to do this? I'm not quite sure how create a method, which would return different types of values (C# rookie;)). As you can see, the tagElement could be (so far) either Ranorex.InputTag or Ranorex.SelectTag, most probably more in future. Should I use "out" keyword in method definition or is there a better approach?
//get preferred capability of selected element var tagType = unknownTagElement.Element.PreferredCapability.DisplayName; if (tagType == "InputTag") { //create adapter with correct capability Ranorex.InputTag tagElement = unknownTagElement.Element; //get TagName tagName = tagElement.Name.ToString(); if (tagElement.Type=="radio" | tagElement.Type=="checkbox") { //get attribute value tagValue = tagElement.Element.GetAttributeValueText("Checked"); } else { //get attribute value tagValue = tagElement.Element.GetAttributeValueText("TagValue"); } } else if (tagType == "SelectTag") { //create adapter with correct capability Ranorex.SelectTag tagElement = unknownTagElement.Element; //get TagName tagName = tagElement.Name.ToString(); //get TagValue tagValue = tagElement.Element.GetAttributeValueText("TagValue"); }