함수 대리자를 사용하여 매개 변수 사용하여 메서드를 호출 할 방법을 찾고 있어요.함수 대리자 매개 변수 사용하여 C#
대신 processOperationB를 호출하는 대신 위임 함수를 사용할 수 있습니다. 그러나 아래의 방법이 달성 될 수있는 어떤 방법을 찾고 있습니다.
public class Client
{
public AOutput OperationA (string param1, string param2)
{
//Some Operation
}
public BOutput OperationB(string param1, string param2)
{
//Some Operation
}
}
public class Manager
{
private Client cl;
public Manager()
{
cl=new Client();
}
private void processOperationA(string param1, string param2)
{
var res = cl.OperationA(param1,param2);
//...
}
private void processOperationB(string param1, string param2)
{
var res = cl.OperationB(param1,param2);
// trying to Call using the GetData , in that case I could get rid of individual menthods for processOperationA, processOperationB
var res= GetData<BOutput>(x=> x.OperationB(param1,param2));
}
// It could have been done using Action, but it should return a value
private T GetData<T>(Func<Client,T> delegateMethod)
{
// how a Function delegate with params can be invoked
// Compiler expects the arguments to be passed here. But have already passed all params .
delegateMethod();
}
}
좋아, 그 코드의 문제점은 무엇입니까? 오류가 있습니까? 어떤 오류입니까? – JLRishe
당신이 무엇을하려고하는지 명확하지 않습니다 ... 코드를 직접 실행할 수있는 것처럼 왜 GetData를 호출 할 것인가 ... – Phil1970