리플렉션 및 제네릭을 사용하여 대리인 컬렉션을 만드는 데 문제가 있습니다.Delegate.CreateDelegate() 및 제네릭 : 대상 메서드에 대한 바인딩 오류
공통 메서드 시그니처를 공유하는 Ally 메서드에서 대리자 컬렉션을 만들려고합니다. 요리
public class Classy
{
public string FirstMethod<T1, T2>(string id, Func<T1, int, IEnumerable<T2>> del);
public string SecondMethod<T1, T2>(string id, Func<T1, int, IEnumerable<T2>> del);
public string ThirdMethod<T1, T2>(string id, Func<T1, int, IEnumerable<T2>> del);
// And so on...
}
그리고 제네릭 :
// This is the Classy's shared method signature
public delegate string classyDelegate<out T1, in T2>(string id, Func<T1, int, IEnumerable<T2>> filter);
// And the linq-way to get the collection of delegates from Classy
(
from method in typeof(Classy).GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic)
let delegateType = typeof(classyDelegate<,>)
select Delegate.CreateDelegate(delegateType, method)
).ToList();
그러나 Delegate.CreateDelegate(delegateType, method)
오류가 방법을 대상으로 바인딩 말하는 ArgumentException이 발생합니다. :/
내가 뭘 잘못하고 있니?
안녕하세요 Driis! 당신의 응답을 주셔서 감사합니다. '메소드 시그니처에 대한 분산을 선언 할 수 없습니까?'라는 의미는 무엇입니까? – SDReyes
그는 일반적인 인수에'out'과'in' 키워드를 의미합니다. – gix
클래스의 메서드 시그니처에 out 및 in 한정자를 사용할 수 없다는 것을 의미합니다. 델리게이트 및 인터페이스 선언에만 사용할 수 있습니다. – driis