문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top