✅ Getting multiple return values from a method called using InvokeMember
So I'm using InvokeMember to call methods on a variety of different objects, all of which use a tuple return type to return multiple values. The issue I'm having is when one of these methods does return the multiple values, I'm getting an InvalidCastException. This is the implementation I've got for the InvokeMember - is it possible to use Tuple return types with InvokeMember, or am I just doing it wrong here?
21 Replies
Ignore my awful class naming
whats the exact cast error? it should give the exact return type
thats the difference,
ValueTuple<T1, T2>
(a struct), vs Tuple<T1, T2>
(a class)So do I need to define a specific tuple class first before using it to cast the returned object from the method to returnValues?
Or is it that the method is returning the struct?
no, instead of casting to
Tuple
, u should cast to ValueTuple
Ah, okay
Is that due to my implementation, or is this just how this works with InvokeMethod, It should be a struct?
if the method is something like
public (int, int) Example();
the return type is ValueTuple<int, int>
u can not simply cast a ValueTuple
to a Tuple
cap5lut
REPL Result: Failure
Exception: CompilationErrorException
Compile: 391.152ms | Execution: 0.000ms | React with ❌ to remove this embed.
it highlights this part:
(Tuple<int, int>)vt
Ahh, okay
So from what I understand, I should still be able to access the values in a ValueTuple the same way though, right? After changing to a ValueTuple type, I now cant access them using the
returnTypes.Item1
wayAh, don't worry, I figured it out, thank you
Was giving me this
But apparently it should be
returnTypes.Value.Item1
ah yeah,
Nullable<T>
is weird 😂Thanks for your help!
glad i could o7
if this answered ur questions, dont forget to $close the thread
Use the /close command to mark a forum thread as answered
Shall do