Question

I have a method that takes an ApiController Type parameter as such:

private List<MethodInfo> GetMethods<T>()
{
  ...
}

I am trying to create a Type to pass to this method using the following:

  Type controller = Assembly.GetCallingAssembly().GetTypes().Where(
      type => type.Name.Contains(schema) && type.IsSubclassOf(typeof(ApiController))).First();

  var collection = GetMethods<controller>();

Well, "type or namespace controller could not be found..." Driving me nuts!

I'm sure there is something easy I'm not seeing here, but I can't figure it out.

Était-ce utile?

La solution

Generic type parameters have to be a type recognized by the compiler, not something created at runtime. controller is a variable name, not a type the compiler can recognize at compile time, hence the error. http://msdn.microsoft.com/en-us/library/0zk36dx2.aspx

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top