delegates

iPhone CoreData fetch from delegate?

Hi All, I've got a program which is working and uses Core Data for storage. However, I'm not entirely sure if I should be keeping my fetch/update methods exclusively to the app delegate? One example is for a question within the app. The question has a "left" and a "right" statement. The delegate currently creates the new QuestionVC ...

method subscription vs lambda delegate subscription - Which and why?

I have seen some people leaning on handing methods to callbacks/events and then sometimes just handing them lambdas. Can anybody speak to any difference between the two? I would have originally thought them to be the same, but the inconsistency I have seen implemented sometimes makes me wonder if there is a case where one is preferable ...

Creating delegate to pass function with parameters (.net 2.0)

Forgive me if this is documented somewhere, but is there any nice way to create a MethodInvoker which will perform a specified function with specified arguments (capturing the argument values when the MethodInvoker is created)? I've sometimes done things by using a wrapper class, but wonder if that's the best approach. Should I be doin...

How to return Boolean value from Action Delegate under List.ForEach()

I am trying to implement following thing. I need to return true if any of the button is found to be changed. I don't want any more looping. Since ForEach is looking for Action Type Delegate. So is it possible to return bool value from within a deletage public bool AreSettingChanged() { objRpmButtonHolder.RpmButtonCollection.ForEach...

passing an unmanaged function pointer callback to managed code using C++ interop

Hi all, I'm trying to add some managed code into an existing c++ GUI application. I'd like to get a functional callback working...specifically, I'd like to pass a method pointer from UNMANAGED code to MANAGED code and have the managed code invoke the callback. I'm looking at something like this: typedef int (__stdcall *ANSWERCB)(int)...

Reflection and private delegate fields of events in c#

I'm probably doing something silly, but here it goes. I'm trying to get the FieldInfo from a public event via reflection. Check this function: public void PlotAllFields(Type type) { BindingFlags all = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public; FieldInfo[] fields = type.GetFields(all); Con...

How to raise Onload/OnUnload event from FrameworkElement for unit testing purposes?

As you can see here, I can't use reflection to get the multicast delegates of the private fields behind these FrameworkElement events because they aren't field-like. So how to do it? ...

Call a delegate's method within a background

Hi, this is my first question here, so excuse me if I made any mistakes! In my iPhone project I have a method running in a thread which takes a long time to execute (that's why it runs in a thread). [NSThread detachNewThreadSelector:@selector(methodToBeCalledInAThread) toTarget:self withObject:nil]; // ... -(void)methodToBeCalledInAT...

Serialize Composed Func?

This works fine: Func<string, string> func1 = s => s + "func"; ViewState["function"] = func1; However, this does not: Func<string, string> func1 = s => s + "func"; Func<string, string> func2 = s => func1(s); ViewState["function"] = func2; It throws a runtime serialization exception: Type 'MyProjectName._Default...

Class design question

Hi all: To put this in concise language... Aim: To create a class which can load and save a list of objects to/from a data source. Current Method: I have created a class which accepts two delegates as construction parameters: private class Foo { public delegate List<object> LoadObjectsDelegate(); public delegate void Sav...

Meaning of () => Operator in C#, if it exists

Hello everybody, I read this interesting line here, in an answer by Jon Skeet. The interesting line is this, where he advocated using a delegate: Log.Info("I did something: {0}", () => action.GenerateDescription()); Question is, what is this ()=> operator, I wonder? I tried Googling it but since it's made of symbols Google couldn't b...

C# async callback still on background thread...help! (preferably without InvokeRequired)

Hi there, I am writing a very simple asynchronous helper class to go along with my project. The purpose of the class is that it allows a method to be run on a background thread. Here is the code; internal class AsyncHelper { private readonly Stopwatch timer = new Stopwatch(); internal event DownloadCompleteHa...

Delegates in python

I've implemented this short example to try to demonstrate a simple delegation pattern. My question is. Does this look like I've understood delegation right? class Handler: def __init__(self, parent = None): self.parent = parent def Handle(self, event): handler = 'Handle_' +event if hasattr(self, handler):...

Objective-C design pattern question about delegate

I have a class which implements many delegate methods. How to group the delegate methods into different classes by the protocol they belongs to and use them in the original class? ...

Question regarding passing data to the delegate in iOS

So I have a tableview as a root screen and an add button that presents a new screen that has a datepicker. When I present the new view, I set the root screen to delegate. Now, I need to pass the data from the uidatepicker screen back to its delegate, but I can't remember how that was supposed to work... I know that I should be able to...

Interchanging delegate/function and interface in D2

I'd like to be able to define a function that takes an interface, but can be fulfilled with a delegate or function that provide the same functionality. For example, in C++ I can write something like: typedef std::function<int (float)> toInt; void fun(toInt dg) { ... } struct impl1 { int operator()(float x) { ... } }; int impl2(fl...

jQuery unbind Live/Delegate events with namespace

Hi! I'm trying to unbind a live event (have tried with .live and with .delegate). When I want to unbind it I have 3 different options: unbind "click", unbind "click.namespace1" or unbind ".namespace1". They all do different things: first one unbind all click events (is not what I want), the second one unbind only the events at "click" ...

Property get/set Delegates for runtime reflected class.

I understand that Delegates offer high performance reflection maybe just 15% slower than regular explicit c# code. However all the examples I can find on stackoverflow are based on prior knowledge of the type of a method/property being accessed via a delegate. Given such prior knowledge of a class, why resort to reflected Delegate acces...

How do Boost Bind, Boost Function, Boost Signals and C++ function pointers all relate to each other?

As the title might convey, I'm having problems seeing how Boost Bind, Boost Function, Boost Signals and C++ function pointers all play together. From my understanding, Boost Bind and Boost Function in conjunction work like Signals while Signals is an abstraction above Bind and Function. Also, compared to standard C++ function pointers...

How to init NSObject<protocol> pointer so it responds to delegate SEL?

I have such thing in my class definition: NSObject<SomeProtocol> *dataDelegate; I have custom -(id)init method in which I should init this NSObject. How do I do it if I want it to respond selectors from SomeProtocol? ...