2017-09-24 1 views
1

외부 라이브러리를 내 라이브러리로 포팅하고 있지만 UWP 환경에서 개발 중입니다. Windows 10에 대해서는 분명히 Delegate.Clone이 없습니다. 어떻게 동일한 기능을 수행 할 수 있습니까? 이에 대한 해결 방법이 있습니까?Delegate.Clone in UWP

_listChanging.Clone() // list changing is instance of some delegate. 
         // unfortunately this method does not exist in UWP 

이 맞습니까?

_listChanging.GetMethodInfo().CreateDelegate(_listChanging.GetType(), _listChanging.Target); 

답변

2

당신이 달성하기 위해 정적 Combine method를 사용할 수 있습니다

delegate void MyDelegate(string s); 
event MyDelegate TestEvent; 

private void TestCloning() 
{ 
    TestEvent += Testing; 
    TestEvent += Testing2; 

    var eventClone = (MyDelegate)Delegate.Combine(TestEvent.GetInvocationList()); 

    TestEvent("original"); 
    eventClone("clone"); 

    Debug.WriteLine("Removing handler from original..."); 
    TestEvent -= Testing2; 

    TestEvent("original"); 
    eventClone("clone"); 
} 

private void Testing2(string s) 
{ 
    Debug.WriteLine("Testing2 was called with {0}", s); 
} 

void Testing(string s) 
{ 
    Debug.WriteLine("Testing was called with {0}", s); 
} 

출력 :

Testing was called with original 
Testing2 was called with original 
Testing was called with clone 
Testing2 was called with clone 
Removing handler from original... 
Testing was called with original 
Testing was called with clone 
Testing2 was called with clone