delegates

C# to VB6 COM events (“object or class does not support the set of events”)

帅比萌擦擦* 提交于 2019-12-30 06:46:05
问题 Really pulling my hair out with this one... I have a C# project with an interface defined as: /* Externally Accessible API */ [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface ISerial { [DispId(1)] bool Startup(); [DispId(2)] bool Shutdown(); [DispId(3)] bool UserInput_FloorButton(int floor_number); [DispId(4)] bool Initialize(); } /* Externally Accesssible Event API */ [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface ISerialEvent { [DispId(5)]

Automated delegation in Java

故事扮演 提交于 2019-12-30 06:36:11
问题 I would like to add some functionality to an object that will be generated at runtime. However, the interface for this object is very large (and not under my control). I would like to wrap the object in my own class which adds the functionality I want and delegates the standard interface functionality to the original object - is there any way to do this in Java without creating a 1-line copy-paste delegator method for every method in the interface? What I want to avoid: class MyFoo implements

Automated delegation in Java

纵然是瞬间 提交于 2019-12-30 06:35:08
问题 I would like to add some functionality to an object that will be generated at runtime. However, the interface for this object is very large (and not under my control). I would like to wrap the object in my own class which adds the functionality I want and delegates the standard interface functionality to the original object - is there any way to do this in Java without creating a 1-line copy-paste delegator method for every method in the interface? What I want to avoid: class MyFoo implements

UIImagePickerController delegate warning

随声附和 提交于 2019-12-30 06:02:07
问题 I've just put a photo picker into my project, and everything works fine. The only thing is it insists on giving me the following warning where I set the delegate - Assigning to 'id<UINavigationControllerDelegate,UIImagePickerDelegate>' from incompatible type 'AddTargetViewController *' I have set up the delegate in the AddTargetViewController.h in the normal way - @interface AddTargetViewController : UIViewController <UIImagePickerControllerDelegate> and I can't see anything wrong. As I say,

Events of a non-delegate type

随声附和 提交于 2019-12-30 05:05:46
问题 I've implemented a class that looks like this interface: [ImmutableObject(true)] public interface ICustomEvent { void Invoke(object sender, EventArgs e); ICustomEvent Combine(EventHandler handler); ICustomEvent Remove(EventHandler handler); ICustomEvent Combine(ICustomEvent other); ICustomEvent Remove(ICustomEvent other); } This CustomEvent class works much like a MulticastDelegate. It can invoked. It can be combined with another CustomEvent. And a CustomEvent can be removed from another

How to attach event handler to an event using reflection?

自作多情 提交于 2019-12-30 04:42:09
问题 I know about EventInfo.AddEventHandler(...) method which can be used to attach handler to an event. But what should be done if i can not even define proper signature of the event handler, as in, i don't even have reference to the event args expected by the handler? I will explain the problem with the proper code. // Scenario when I have everything available in my solution, Zero Reflection Scenario. internal class SendCommentsManager { public void Customize(IRFQWindowManager rfqWindowManager)

Please Explain .NET Delegates

北城以北 提交于 2019-12-30 02:08:15
问题 So I read MSDN and Stack Overflow. I understand what the Action Delegate does in general but it is not clicking no matter how many examples I do. In general, the same goes for the idea of delegates. So here is my question. When you have a function like this: public GetCustomers(Action<IEnumerable<Customer>,Exception> callBack) { } What is this, and what should I pass to it? 回答1: it expects a function that takes IEnumerable and Exception and returns void. void SendExceptionToCustomers

Is using Action.Invoke considered best practice?

孤街醉人 提交于 2019-12-30 01:43:46
问题 If I have the below code, should I just call the Action or should it call Action.Invoke? public class ClassA { public event Action<string> OnAdd; private void SomethingHappened() { if (OnAdd != null) OnAdd("It Happened"); //Should it be OnAdd.Invoke("It Happened") ??????? } } public class ClassB { public ClassB() { var myClass = new ClassA(); myClass.OnAdd += Add; } private void Add(string Input) { //do something } } 回答1: The two are equivalent, the compiler converts OnAdd("It Happened");

Can a method be attached to a delegate with predefined parameters?

…衆ロ難τιáo~ 提交于 2019-12-29 09:05:49
问题 Sometimes I encounter cases where I have to attach a method to a delegate but the signature doesn't match, like trying to attach abc down there to somedelegate with the string parameter being "hi". public class test { //... public void abc(int i, string x) { //Do Something } //... } public class test2 { somedelegate x; //... public test2() { //Do Something test y = new test(); x += y.abc(,"hi"); } delegate void somedelegate(int i); } I can work it around by creating another delegate with the

How can I pass several methods (with parameters) AS a parameter?

时光毁灭记忆、已成空白 提交于 2019-12-29 08:15:12
问题 Suppose I have the following WCF code: try { ServiceClient proxy = new ServiceClient(); proxy.ClientCredentials.UserName.UserName = "user"; proxy.ClientCredentials.UserName.Password = "password"; proxy.GetData(2); if (proxy.State = CommunicationState.Opened) { proxy.GetData("data"); } proxy.Close(); } catch (FaultException ex) { // handle the exception } And since I notice that the try...catch and other logic is repetitive, not to mention that setting up a WCF call is expensive, I want to