delegates

What is the best way to convert Action<T> to Func<T,Tres>?

喜欢而已 提交于 2019-12-18 07:29:35
问题 I have two functions in my class with this signatures, public static TResult Execute<TResult>(Func<T, TResult> remoteCall); public static void Execute(Action<T> remoteCall) How can I pass the same delegate in the second method to the first one? Creating method with Delegate argument is not a way, because I am loosing some exception informations Thanks a lot! 回答1: Wrap it in a delegate of type Func<T, TResult> with a dummy return value, e.g. public static void Execute(Action<T> remoteCall) {

9Implementing Nuance Speech Recognition on Swift, cannot listen to onResult, onError… events

拟墨画扇 提交于 2019-12-18 07:18:10
问题 I have two parts of my Speech Recon project with Nuance, the .h file of a module (ObjectiveC) and a ViewController (swift). I want to set up a SpeechRecognition object in my swift viewController , and listen to onBegin, onStop... and such methods. The only way to make it compile is to use nil as the delegate parameter to initialize the SpeechRecon object. Obviously this is not good because my onStart... and onFinish functions don´t trigger. I have implemented a protocol to the SKRecogniser

.net delegate without target slower than with target

非 Y 不嫁゛ 提交于 2019-12-18 07:10:16
问题 When I execute the following code in release mode on my machine the execution of a delegate with a non null target is always slightly faster than when the delegate has a null target (I expected it to be equivalent or slower). I'm really not looking for micro optimization but I was wondering why this is the case? static void Main(string[] args) { // Warmup code long durationWithTarget = MeasureDuration(() => new DelegatePerformanceTester(withTarget: true).Run()); Console.WriteLine($"With

Android: Making a button visible once webview is done scrolling

試著忘記壹切 提交于 2019-12-18 06:27:43
问题 I have a webview which shows an html file. When the user scrolls to the bottom of this file in webview, I want a button that was previously hidden to show up, which the user can then press to do some activity I did something similar in iOS, where I just set the delegate to the ViewController and just set the button as visible. How do I do something similar on Android? I noticed there isn't a callback method like in iOS. Edit: Right now, I have an activity with 2 objects: a webview containing

Android: Making a button visible once webview is done scrolling

给你一囗甜甜゛ 提交于 2019-12-18 06:27:06
问题 I have a webview which shows an html file. When the user scrolls to the bottom of this file in webview, I want a button that was previously hidden to show up, which the user can then press to do some activity I did something similar in iOS, where I just set the delegate to the ViewController and just set the button as visible. How do I do something similar on Android? I noticed there isn't a callback method like in iOS. Edit: Right now, I have an activity with 2 objects: a webview containing

C# removing an event handler

删除回忆录丶 提交于 2019-12-18 05:29:05
问题 I've been doing this for a while, but I haven't noticed that I've been using a new each time I remove an event handler. Am I supposed to be creating a new object? Basically is there a difference between 1 and 2? ethernetdevice.PcapOnPacketArrival -= new SharpPcap.PacketArrivalEvent(ArrivalResponseHandler); ethernetdevice.PcapOnPacketArrival -= ArrivalResponseHandler; EDIT: Okay this is a duplicate. Sorry about that. Answer posted here. Two delegates of the same type with the same targets,

UITableView delegate action when tableView is scrolled?

寵の児 提交于 2019-12-18 05:28:29
问题 Is there a UITableView delegate-action that runs when the tableView is being scrolled? This is probably really easy, but I can't find it. Thank you :) 回答1: UITableView is a subclass of UIScrollView and table's delegate can also act as a scroll view's delegate. So you can use all methods from UIScrollViewDelegate for your table (implementing them in table's delegate), e.g. - (void)scrollViewDidScroll:(UIScrollView *)scrollView (scrollView parameter in this case will be pointer to your

C# new [delegate] not necessary?

守給你的承諾、 提交于 2019-12-18 05:04:20
问题 I've been playing with HttpWebRequest s lately, and in the tutorials they always do: IAsyncResult result = request.BeginGetResponse( new AsyncCallback(UpdateItem),state); But new AsyncCallback doesn't seem to be necesary. If UpdateItem has the right signature, then there doesn't seem to be a problem. So why do people include it? Does it do anything at all? 回答1: It's the same thing, mostly (there are a few overload rules to think about, although not in this simple example). But in previous

C# new [delegate] not necessary?

拥有回忆 提交于 2019-12-18 05:04:04
问题 I've been playing with HttpWebRequest s lately, and in the tutorials they always do: IAsyncResult result = request.BeginGetResponse( new AsyncCallback(UpdateItem),state); But new AsyncCallback doesn't seem to be necesary. If UpdateItem has the right signature, then there doesn't seem to be a problem. So why do people include it? Does it do anything at all? 回答1: It's the same thing, mostly (there are a few overload rules to think about, although not in this simple example). But in previous

Events/Delegates In Java or C#

↘锁芯ラ 提交于 2019-12-18 04:54:21
问题 I've been trying to learn about events/delegates, but am confused about the relationship between the two. I know that delegates allow you to invoke different functions without needing to know what particular function is being invoked. (eg: a graphing function needs to accept inputs that are different functions to be graphed). But I don't see how delegates are used in Events. Can someone construct a simple example (in pseudocode or C# or Java) that illustrates the workings of Delegates as