All Questions
Tagged with types reflection
572
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<...
0
votes
3
answers
82
views
Can a Go interface receive any function, regardless of its signature?
EDIT: A couple of the answers have suggested changing the signature of the RegisterHandler function, however as part of the original question I asked if it were possible to further restict the types, ...
0
votes
1
answer
47
views
Can I check if ReflectionType is instance of another type?
I want to check if a callable's return type is an instance of another type. For example, let's say I a have:
A class Pigeon which extends Animal.
A function addSupplier() which takes a callable ...
1
vote
1
answer
80
views
Convert value with a type to value of another type in Kotlin generically
I have a map with pairs of KType to a value in String, and I wish to convert those values to the type of KType in its pair(for example, convert "123" to an Int with the value 123).
Knowing ...
0
votes
1
answer
82
views
Is there a good way to make number type fit "method.Call" in golang?
Code Go Playground :
package main
import (
"fmt"
"reflect"
)
func (s StructWithManyMethods) Func1(a int, b uint, c float64) {
fmt.Printf("func:Func1 a:%d b:%d c:%...
3
votes
1
answer
189
views
Get a dictionary of a generic type based on a runtime value
I wish to declare a dictionary based on a runtime type. So, instead of doing this:
IEnumerable dict = null;
if(type == typeof(SomeType)) dict = new Dictionary<SomeType, string>()
if(type == ...
3
votes
1
answer
66
views
Get the type name of a Dictionary with generics in C#
Is there an easy or elegant way to get the type name of a Dictionary with the generic types in C#?
Currently I have this code works:
if (property.PropertyType.Name == "Dictionary`2")
{
...
0
votes
1
answer
144
views
How to register all subtypes of a generic type?
I'm trying to distill this (and more):
builder.RegisterType<ZipCodeRepository<ZipCode>>.AsImplementedInterfaces();
builder.RegisterType<MemberRepository<Member>>....
0
votes
1
answer
73
views
Replace Generic Types In `System.Type[]` With Types
Say one has a generic definition MethodInfo object, that is, a MethodInfo object such that methodInfo.IsGenericMethodDefinition == true:
MethodInfo methodInfo = somethingCool;
Say also that they also ...
0
votes
2
answers
62
views
Get implementer class type
I have the below code
public abstract class abstract1
{
public void Test1()
{
// << Log the caller >>
// Environment.StackTrace gives no information about class1
...
0
votes
0
answers
65
views
Blazor session storage - How to pass unknown type
I would like to create a method to handle returning the objects in SessionStorage throughout my Blazor app.
The error I am getting of course is: 'obj' is a variable but is used like a type
Is there a ...
0
votes
1
answer
685
views
How can I find the defined type of a property/field at runtime in TypeScript?
I am trying to get the type of a property/field in TypeScript. Specifically, from the property decorator. The property does not have a value set so I can not derive it from the type of the value. ...
0
votes
2
answers
84
views
Can I perform type conversion using the type found through Java reflection?
Can I perform type conversion using the type found through Java reflection?
public class Dto {
private String name;
private int age;
public Dto(){}
}
It has two fields of different types....
-5
votes
2
answers
87
views
How to get values from the array, that put into the object? [closed]
I am making json parser so I need the universal method, thats why I can not int[] arr = obj as int[];
int[] array = new int[] { 0, 1, 2 };
object obj = array;
//I need to get value from the 'obj'
I ...
2
votes
1
answer
73
views
What is the difference between the metaclass Type and the metaclass Class in Java?
What is the difference between the metaclass Type and the metaclass Class in Java?
When should I be using one or the other when programming with reflection?
Instances of the class Class represent ...