Hi all, below at the bottom are 2 nearly identical overloads for the same
method. As you can see the algorithm is exactly the same. However try as I
may I cannot seem too create a usefull Generic method, i.e. one that compiles.
What I would like to be able to do is something like the following when I
call it.
this.UpdateAnswer<TextBox>(question, answer);
Or better yet.
this.UpdateAnswer<typeof(SomeUiElement.GetType())> (question, answer);
Is this type of thing at all possible with generics or am I headed down the
wrong path?
private void UpdateAnswer(PaginationPageQuestion question, TextBox answer)
{
if (answer != null)
{
question.Answer = !answer.Text.Trim().Equals(string.Empty) ?
answer.Text.Trim() :
null
;
}
}
private void UpdateAnswer(PaginationPageQuestion question, ComboBox
answer)
{
if (answer != null)
{
question.Answer = !answer.Text.Trim().Equals(string.Empty) ?
answer.Text.Trim() :
null
;
}
}
--
Thank you,
John