delegates

What is the difference between new Action() and a lambda?

So when I write something like this Action action = new Action(()=>_myMessage = "hello"); Refactor Pro! Highlights this as a redundant delegate creation and allows me to to shorten it to Action action = () => _myMessage="hello"; And this usually works great. Usually, but not always. For example, Rhino Mocks has an extension metho...

Anonymous delegate implementation in Objective-C?

Is it possible to declare anonymous implementations of things like Delegates in Objective-C. I think I have the terminology right, but here's a java example: myClass.addListener(new FancyInterfaceListener({ void onListenerInterestingAction(Action a){ ....interesting stuff here } }); So for example to handle an UIAction...

Automatic generation of wrappers to prevent "malicious downcast"?

If you implement an interface in Java, there is nothing to prevent the caller from looking at what concrete implementation you have supplied, casting to that class and calling methods that are not in the interface. I believe this is called "malicious downcasting". A way to prevent this is to create a wrapper that only has the interface'...

Generating Delegate Types dynamically in C#.

We have a requirement where we need to generate delegate types on the fly. We need to generate delegates given the input parameters and the output. Both input and output would be simple types. eg, we need to generate int Del(int, int, int, string) and int Del2(int, int, string, int) Any pointers on how to get started on this would...

Delegate vs. delegate keyword (.NET)

Hello, If you like to create custom delegates you would use the delegate keyword in lowercase. What can you do with the actual Delegate Class? What is this good for? Don't understand the exact difference. Thanks Kave ...

C#: Using new in a Func<T>

I was wondering, after having read this question... he has this code: public static T FindOrCreate<T>(this Table<T> table, Func<T, bool> find) where T : new() { T val = table.FirstOrDefault(find); if (val == null) { val = new T(); table.InsertOnSubmit(val); } return val; } Would it be possible ...

Creating a reusable method timeout class in C#

I am trying to create a class that lets me call methods with a specified timout. I have the actual timeout implementation working, but am having trouble encapsulating this into a class successfully. I have decided at this time to limit myself to working with just the 5 Action delegates to put a timeout on methods that take 0 - 4 argumen...

Why would you use Expression<Func<T>> rather than Func<T>?

I understand lambdas and the Func and Action delegates. But expressions stump me. In what circumstances would you use an Expression<Func<T>> rather than a plain old Func<T>? ...

In C#, how would I use a delegate to manipulate a form from a custom class I made?

I know how to manipulate a textbox on a Form, from a Form, but I do not know how to manipulate a textbox from a CLASS in it's own file to a Form. Can someone explain to me how I would write a Delegate & a CallBack so I could simply call a method from a Class in a different file, and change stuff on a textbox from a different form? I do...

How to pass data to a UITabBarController

Hi, my app features a UITabBarController, which brings up some views. In the AppDelegate, I have to pass a (custom) model to it. Is the best way subclassing, or is there some better method? If I get it managed to have the model (e.g. Notes) in my UITabBarController, how do I access it out of the ViewControllers? Regards ...

asp.net: how do I wire up LinkButton-like linking functionality with delegates on a table cell background?

I'm using ASP.NET user controls. I'm passing values to another user control via command arguments through a link button as follows: asp:LinkButton ID="ZoomPhotoLinkButton" CommandArgument='<%#(Eval("conid"))%>' CommandName="PassItemId" runat="server">Zoom It What I really want is to make the entire background cell of my table clickab...

How to exit a Generic list ForEach with delegate ?

How do i exit a Generic list ForEach with a delegate? Break or return doesn't work. Example: Peoples.ForEach(delegate(People someone) { if(someone.Name == "foo") ???? What to do to exit immediatly ? }); ...

Refactoring with Lambda's and Delegates

I've just installed VS2008 and have run into a problem that I'm sure can be solved with either lambda's or delegates (or a combination!). private string ReadData(TcpClient s, string terminator) { // Reads a byte steam into a string builder until either data is unavailable or the terminator has not been reached va...

Thread Finished Event in Python

Hello, I have a PyQt program, in this program I start a new thread for drawing a complicated image. I want to know when the thread has finished so I can print the image on the form. The only obstacle I'm facing is that I need to invoke the method of drawing from inside the GUI thread, so I want a way to tell the GUI thread to do someth...

Avoid duplicate event subscriptions in C#

How would you suggest the best way of avoiding duplicate event subscriptions? if this line of code executes in two places, the event will get ran twice. I'm trying to avoid 3rd party events from subscribing twice. theOBject.TheEvent += RunMyCode; In my delegate setter, I can effectively run this ... theOBject.TheEvent -= RunMyCode; t...

Writing Extension methods with Action / Func / Delegates / Lambda in VB and C#

hey guys. Firstly I can't get my head around the functional / Lambda aspects of .NET 3.5. I use these features everyday in LINQ, but my problem is understanding the implementation, and what they really mean (Lambda? System.Func? etc etc) With this in mind, how would the following be achieved: As an example, I'd like to have an Extensi...

What describes the Application Delegate best? How does it fit into the whole concept?

Well I think to know what the App Delegate does. It has some nice methods like -applicationDidFinishLaunching which will be called when the app has finished launching, and so on. But what's that actually? Is that some object instantiated in the UIApplicationMain function? And how does it work that every class in my app has access to tha...

Using Delegates for handling an event.

Sorry, that's the best subject I can come up with, if I understood the solution better, I could probably phrase a better subject line. I am using a great grid control, Super List,l located here: http://www.codeproject.com/KB/list/outlooklistcontrol.aspx?fid=449232&amp;df=90&amp;mpp=25&amp;noise=3&amp;sort=Position&amp;view=Quick&amp;fr...

Silverlight async calls and anonymous methods....

I know there are a couple of debates on this kind of thing.... At any rate, I have several cases where I need to populate combobox items based on enumerations returned from the WCF service. In an effort to keep code clean, I started this approach. After looking into it more, I don't think the this works as well is initially thought... ...

In WCF is it possible to pass a delegate to the remote object?

Is it possible to pass a delegate to a WCF remote object from the client and have the remote object execute the delegate? I would guess not since a delgate is a function pointer for the client process. My goal is to have an interface structure that I can "subscribe" to events from a client to the interface. I would pass a delgate from...