Thinker
Thinker
CC#
Created by Strikeeaglechase on 12/23/2024 in #help
Cast value's in object[] to type based on result from method.GetParameters
You could have something like an IWrapper interface with a single object Inner { get; } property, then you can check whether an object is an IWrapper and then get the inner value.
9 replies
CC#
Created by Strikeeaglechase on 12/23/2024 in #help
Cast value's in object[] to type based on result from method.GetParameters
... what are you using the wrapper for anyway?
9 replies
CC#
Created by Strikeeaglechase on 12/23/2024 in #help
Cast value's in object[] to type based on result from method.GetParameters
What you could do is just get the int from the IntWrapper instead of passing the wrapper directly
9 replies
CC#
Created by Strikeeaglechase on 12/23/2024 in #help
Cast value's in object[] to type based on result from method.GetParameters
You can't really do this kind of conversion automatically, you have to invoke the method with the exact parameters specified.
9 replies
CC#
Created by Strikeeaglechase on 12/23/2024 in #help
Cast value's in object[] to type based on result from method.GetParameters
Convert.ChangeType will almost never do what you actually want fyi
9 replies
CC#
Created by Aon on 12/23/2024 in #help
Is is possible to use variable in generic >> EventCallback.Factory.Create<VarType>()
Can you show a piece of your actual code where you want this?
5 replies
CC#
Created by Aon on 12/23/2024 in #help
Is is possible to use variable in generic >> EventCallback.Factory.Create<VarType>()
(however in this example there's not really a reason to use a variable for the type)
5 replies
CC#
Created by Aon on 12/23/2024 in #help
Is is possible to use variable in generic >> EventCallback.Factory.Create<VarType>()
No, generics are compile-time only
5 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
That's a fundamental universal truth of C#
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
If a method takes a Dictionary<int, string> then it can only take a Dictionary<int, string>
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
We're not banging stones together, we're not Python
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
The compiler does that for you
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
You don't need to do these kinds of type checks yourself, ever
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
Just do this
public void YourMethod<TKey, TValue>(Dictionary<TKey, TValue> dict)
{
// ...
}
public void YourMethod<TKey, TValue>(Dictionary<TKey, TValue> dict)
{
// ...
}
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
Yeah so... why?
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
wait no
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
I misread
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
oh
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
Although if you already know that dict is a dictionary, why do you need this?
30 replies
CC#
Created by UnemployedNinja on 2/25/2024 in #help
Check if an object is a Dictionary of any type
dict.GetType().GetGenericTypeDefinition() == typeof(Dictionary<,>)
30 replies