All Questions
Tagged with reflection generics
2,051
questions
0
votes
0
answers
22
views
check if given object implements certain generic interface; type argument(s) NOT known [duplicate]
I have some object. I want to check at runtime if it is an IReadOnlyCollection<T> of any T, i.e. I cannot specify that T in my check. So it should return true for e.g. IReadOnlyCollection<...
1
vote
2
answers
39
views
C# reflection: Get static method with multiple generic overloads [duplicate]
How we can get a method such as Tuple.Create that has multiple generic overloads through reflection and use it with our custom generic type arguments?
usecase: the generic type arguments are known ...
1
vote
2
answers
56
views
How to determine if a class is generic via reflection in Kotlin
Suppose we have the following class:
data class KeyValuePair<T : Any>(
val key: String,
val value: T
)
If we reflect against the following instance of this class: KeyValuePair(&...
0
votes
1
answer
30
views
Facing issue while registering service of generic class after reading all class of same type using Reflection Assembly in c# dotnet
I have one generic class defined as below. While registering bean/service getting error that it didn't get register properly.
reflection code:
var types = Assembly.Load("Come.Demo")
...
0
votes
1
answer
40
views
How to call a generic static extension Method using Reflection? [duplicate]
Now before I start: I know that there are many questions like this already that have been answered.
I've tried the lot of them and they just don't seem to work for me and I'm not quite sure what I'm ...
1
vote
1
answer
47
views
GetGenericArguments Recursively on inherited class type in C#?
In C# I have
class Gen1<T1, T2> {}
class Gen2<T2>: Gen1<MyObject, T2> {}
class Ins: Gen2<MyInterface> {}
var ins = new Ins();
Type insType = ins.GetType();
How can I get ...
-1
votes
1
answer
55
views
Passing a generic class to a generic method using reflection
Here's the context:
We have a base class called Body, and many other classes that are inherited from the base class Body.
public class Body{
//...
}
public class A : Body {
//...
}
public class B :...
-1
votes
2
answers
55
views
Invoke generic extension method, with runtime know type as argument [duplicate]
I have a generic extension:
public static T Get<T>(this DataRow row, string columnName)
{
if (row == null || string.IsNullOrWhiteSpace(columnName) || row.IsNull(columnName))
if (...
0
votes
1
answer
43
views
How to invoke method with nested generic type by reflection in C#
I found some examples where generic method is invoked via reflection such as method<T>(). In my case, the generic type is nested in a class method<Class<T>>().
In the example, I ...
-1
votes
1
answer
34
views
Java WildCard list to Specific JavaList
I am working on a fileReader Utility. I am facing some challenge in type casting.
I have a List as below
Class classType= getClassType("");
List<?> list= reader.read(file,classType);
...
1
vote
2
answers
80
views
Simplify making a generic typed value from a reflect value
I have Go code that receives a reflection value and needs to work with it as a generic. To convert the parameter, I've gotten the following to work. Is there a simpler way to achieve the goal?
func ...
0
votes
1
answer
60
views
In Rust, how to inspect values captured by a closure?
In Rust, how can I create a function accpeting a closure as argument that iterates and prints all values captured by the closure reflectively?
For example:
fn print_captured_values<F>(f: F) ...
0
votes
1
answer
49
views
Java Reflection - Get generic type, with possible generic of generic?
I need to determine the generic type(s) applied to a Java Object at runtime. For a situation like Map<String, String>, that is rather easy. I have code that looks like this:
protected Class<...
-1
votes
1
answer
84
views
C# Interfaces with generics and reflection - How to get the intellisense to work
my code (bellow) is working... however, at the moment the solution does not provide me intellisense for the methods that the object rs allows.
How am I able to either "cast" my dynamic ...
1
vote
1
answer
70
views
How to accept any derived class KClass
I have this code
import kotlin.reflect.KClass
fun <T: Any> test(arr: Array<KClass<T>>) {
print(arr)
}
fun main() {
test<Number>(arrayOf(Int::class, Short::class))
}
...