입니다 Func을
Create
메소드를 호출하는 다른 일반 클래스의 제한 조건에 의해 제공됩니다.
이 내가 도달 한 곳이다 : 이전에 내가 최종 대리자를 컴파일 아니에요 내 위의 접근 방식에서
public static class Creator<T>
{
public static void Create()
{
var m = typeof(SomeClass).GetMethod("Create");
var p = Expression.Parameter(typeof(Type));
var e = Expression.Call(m, p);
//at this stage I want to create delegate for calling the 'Create' method,
//then pass typeof(T) as parameter, get returned object,
//and finally cast it to 'T'.
//for eg, I can do it like this:
var f = Expression.Lambda<Func<Type, object>>(e, p).Compile();
Func<T> mainThing =() => (T)f(typeof(T));
//is there a way I can achieve in one step?
}
}
하지만 한 단계. 컴파일하기 전에 캐스팅을 통합하고 Func<T>
을 다시 얻으려면 어떻게해야합니까?
실제 질문에 답변 해 드리겠습니다. – nawfal