C
C#2y ago
arch_il

✅ Convert from string to Type?

public class Foo
{
public string MyTypeInString = "Foo";
}

public static class SomeFunctions
{
public static MyFunction<T>(T input)
{
//
}
}

public class Program
{
public static void Main()
{
Foo f = new();
SomeFunctions.MyFunction<f.MyTypeInString.ConvertToType()>(f);
}
}
public class Foo
{
public string MyTypeInString = "Foo";
}

public static class SomeFunctions
{
public static MyFunction<T>(T input)
{
//
}
}

public class Program
{
public static void Main()
{
Foo f = new();
SomeFunctions.MyFunction<f.MyTypeInString.ConvertToType()>(f);
}
}
How do I get that ConvertToType(this string) function? I believe it should be possible.
3 Replies
ero
ero2y ago
it'll definitely never be possible like that you would need to invoke the MyFunction method entirely through reflection you can't pass an instance of Type as a generic argument
Thinker
Thinker2y ago
Generics are purely for compile-time types
arch_il
arch_ilOP2y ago
aah i see. thanks for help
Want results from more Discord servers?
Add your server