delegates

Why can delegates can be used interchangeably for Class methods and Static functions?

*爱你&永不变心* 提交于 2019-12-23 19:03:04
问题 I've been using delegates for many years, and haven't really given them much thought. But I recently got egg on my face by assuming that delegates included a this reference in the signature when referencing a class method. The below example illustrates the gap in my understanding. public class SomeClass { public SomeClass(int someProperty) { SomeProperty = someProperty; } public int SomeProperty { get; set; } // Throw in a Member field into the mix public int ClassAdd(int x, int y) { return x

ios - App crashes when InApp mail command gets called

孤人 提交于 2019-12-23 18:27:44
问题 When I cll the Message Compose sheet via a UIActionSheet button I get the following error. Sorry these don't mean much to me yet - still learning:-) Could anyone help please? These are the sources of problems that come up. This is in the log: 2012-06-16 19:10:43.437 Multi Web[2665:4013] XPCProxy received bad message: target did not supply method signature for bodyFinishedDrawing 2012-06-16 19:10:43.489 Multi Web[2665:907] _serviceViewControllerReady:error: Error Domain=XPCObjectsErrorDomain

Change label from a different view [closed]

感情迁移 提交于 2019-12-23 18:16:38
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . This is mainly a delegation question because I'm still learning and don't get it. I don't know how to go about creating the delegate I need. I know similar questions have been asked but the solutions don't help

Controlled exception handling in dynamic invocations with variable numbers of parameters

喜欢而已 提交于 2019-12-23 18:11:09
问题 In a thread resolved yesterday, @hvd showed me how to get "control" over exception handling by .Invoke when dealing with delegates of unknown type (an issue seen in libraries like Isis2, where the end-user provides polymorphic event handlers and the library type-matches to decide which to call). Hvd's suggestion revolved around knowing how many arguments the upcall handler received and then using that information to construct a generic of the right type, which allowed him to construct a

Will Delegate with params keyword match any method?

喜你入骨 提交于 2019-12-23 17:52:02
问题 I'm trying to get the following thing done: public delegate void SomeMethod(params object[] parameters); That's my delegate. And i have some method that will run this SomeMethod delegate (whatever's passed) and return me the timespan of execution. public TimeSpan BenchmarkMethod(SomeMethod someMethod, params object[] parameters) { DateTime benchmarkStart = DateTime.Now; someMethod(parameters); DateTime benchmarkFinish = DateTime.Now; return benchmarkFinish - benchmarkStart; } Also i have some

Create a Generic Func delegate using a runtime type

最后都变了- 提交于 2019-12-23 15:01:24
问题 I need to call a generic method that takes a generic Func as one of its parameters, where the Type parameter is known only at runtime. This part of the code is an object mapper, which maps properties between a source and a target object. ViewModelBase is the root of classes that are considered "target" objects. The method that I want to call (defined on ObjectMapperBuilder) has this signature: public static ObjectMapperBuilder<TTarget> Create( Type sourceType, MappingDirection direction, Func

Custom Google Sign In throw exception on GIDSignInDelegate protocol

假如想象 提交于 2019-12-23 14:59:53
问题 I'm writing an iOS app in obj-c and using Google SignIn SDK to do the Google SignIn flow. I wanna be able to customize the button and action a little it so I went ahead implementing the protocols of GIDSignInDelegate myself based on their documentation. But it throws and exception for no reason. Here's the minimal code of my view controller. viewcontroller.m #import "ViewController.h" #import <FBSDKLoginKit/FBSDKLoginKit.h> @interface ViewController () @property (weak, nonatomic) IBOutlet

Custom Google Sign In throw exception on GIDSignInDelegate protocol

我是研究僧i 提交于 2019-12-23 14:59:22
问题 I'm writing an iOS app in obj-c and using Google SignIn SDK to do the Google SignIn flow. I wanna be able to customize the button and action a little it so I went ahead implementing the protocols of GIDSignInDelegate myself based on their documentation. But it throws and exception for no reason. Here's the minimal code of my view controller. viewcontroller.m #import "ViewController.h" #import <FBSDKLoginKit/FBSDKLoginKit.h> @interface ViewController () @property (weak, nonatomic) IBOutlet

Strange decompiled code from event subscribe code in a generic class

风格不统一 提交于 2019-12-23 14:22:13
问题 This simple class public class Test<T> { public static void A(Window wa, Window wb) { wa.Closed += (s, e) => wb.Close(); } } Gets compiled to this (I'm using Reflector to decompile) : public class Test<T> { [CompilerGenerated] private sealed class <>c__DisplayClass1 { public Window wb; public void <A>b__0(object s, EventArgs e) { this.wb.Close(); } } public static void A(Window wa, Window wb) { wa.Closed += delegate(object s, EventArgs e) { base.wb.Close(); }; } } What is the meaning of base

Is it bad practice to use Action and Func all the time instead of making corresponding delegates?

被刻印的时光 ゝ 提交于 2019-12-23 12:24:01
问题 A lot of time when creating simple events in my program that other classes can subscribe to instead of making a delegate and creating an event from the delegate I just create the event with either Action or Func to avoid having to create the delegate. Is there any downsides to doing this? 回答1: Not really, the only downside I can think of is that if you have a logical intention (beyond the parameters and return values expected) that you want the user to satisfy that may get lost using the