I want to get the input value from a function.
I call the function:
Name=GetName(Paul)
Where Paul
is a member of ClassA, ClassB
or Class C
. I want to use the following function to call other functions with Paul
as an input depending on the class Paul
is really in.
public static string GetName(OneOf<ClassA,ClassB,ClassC> input)
{var Variable = input.Match(
ClassA => doSomethingWithA(input),
ClassB => doSomethingWithB(input),
ClassC => doSomethingWithC(input),
);
}
When I try to input.Value
or something like that, I just get the name of the class, but not Paul
, which is unfortunate, because then I don’t have the input I need for my functions doSomethingWith
.
Has someone an idea how to solve this? It doesn’t have to use the OneOf
-Package.
Martin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.