Answer the question
In order to leave comments, you need to log in
Passing a List of Types to a Function
I have a function public void f(Type[] types)
which, let's say, accepts types.
I need to register these types. To me it would look like this:
foreach(var type in types)
{
Engine.RegisterType<type>();
}
public void f<T>()
Answer the question
In order to leave comments, you need to log in
To be honest, it's not very clear why you don't have information about the types that you need to register... and what's wrong with the f option? provide more complete information - there may be a better solution. however, here is the code that solves this problem:
var mi = Engine.GetType().GetMethod("RegisterType"); // хотя, этот тип уж точно известен), лучше typeof
foreach (var type in types)
mi.MakeGenericMethod(new[] { type }).Invoke(null, null);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question