delegates

Create delegate via reflection.

Given an assembly that contains namespace Foo{public class Bar;} How could I create an Action<Foo.Bar> from another assembly without referencing the first assembly at compile time? ...

How to properly dispose of an object

Hi Guys, I am experiencing something weird and have a workaround already, but I don't think I understood it well. If I call the Method below numerous times within a class: public void Method() { Foo a = new Foo(); a.Delegate1Handler = ViewSomething(); } If I call Method() multiple times in one instance of the class that it is in....

Event type can't be Action<> ?

Hello everybody this works public event Func<int,int> createEvents; but why not this ? public event Action<int> createEvents; ...

Are static delegates thread-safe?

Consider this code snippet: public static class ApplicationContext { private static Func<TService> Uninitialized<TService>() { throw new InvalidOperationException(); } public static Func<IAuthenticationProvider> AuthenticationProvider = Uninitialized<IAuthenticationProvider>(); public static Func<IUnitOfWork...

How do I change the background image of my iPhone app?

Hello I have looked around and found some code which so called chooses an image from an array of image objects, but cant find an explanation. I would like to make my app have a background image and the user can select next and previous buttons to scroll through some full screen images, setting them as the background image as they scrol...

Sending information back from delegate [iPhone]

I'm using NSXMLParser in my RootViewController.m file. NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:response_data]; [xmlParser setDelegate:self]; [xmlParser parse]; [xmlParser release]; I'm also implementing this method to add entries to a dictionary defined in RootViewController.m for later use: - (void)parser:(NSXMLPa...

Use event and delegate in subclass

Why cant i use the event declared in Base from Sub? class Program { static void Main(string[] args) { Sub sub = new Sub(); sub.log += new Base.logEvent(sub_log); sub.go(); } static void sub_log(string message, int level) { Console.Out.WriteLine(message + " " + level); } } public ...

is <CLLocationManagerDelegate> necessary to get the users location?

the file that I need the users information in already has a -flipsideViewControllerDelegate-, so Is there a way that I can get the users location coordinates without using the CLLocationManagerDelegate thing? ...

Creating and releasing objects in the same method, while using self as delegate

In objective-c you are responsible for releasing objects you allocate, but what happens when you allocate an object in a method, assign self as the objects delegate, and then release the object. The callbacks from the newly created (and released) object fails at this point, or rather, doesn't happen. - (void)doSomething { MyObj *m...

List<object>.RemoveAll - How to create an appropriate Predicate

This is a bit of noob question - I'm still fairly new to C# and generics and completely new to predicates, delegates and lamda expressions... I have a class 'Enquiries' which contains a generic list of another class called 'Vehicles'. I'm building up the code to add/edit/delete Vehicles from the parent Enquiry. And at the moment, I'm sp...

Accessing Shared Delegate verus iPhone/iPad delegate?

How do I access the shared delegate or the device specific "delegate" in a Universal App? I want to store properties on the Shared delegate and put basic logic there, but if I want to do, say iPhone specific stuff on the iPhone delegate, I would assume that I need to access the two delegates separately. Is this correct? How do I acce...

Why I can`t declare a Delegate at function level?

Sorry if this question is too simple or easy. I just started studying Delegates using C#. When I tried to declare one inside a function I got design time errors, but when I declare the same Delegate at class level, it works fine. Why? If matters this is the code: delegate void Test(); ...

jQuery Delegating to Close Boxy Dialogs

currently, i am using the following to close a dialog <button onClick="Boxy.get(this).hideAndUnload(); return false;">Cancel</button> but i want to do something like <button class="btnCancel">Cancel</button> to close the dialog i tried to use jquery delegate() to close the dialog but it does not work. fyi, i am loading the whole f...

List<>.Find(delegate) issue

I have a multi-column combobox where the datasource is a List<> in my Select Class Select selection = new Select(); RadComboBox1.DataSource = selection.GetAcctUtilCo(e.Text, 10).Skip(e.NumberOfItems); I have a few DataTextFields. My DataValueField is the AcctID. Once an account is selected, I need the datatextfield values to pop...

Can an anonymous delegate unsubscribe itself from an event once it has been fired?

I'm wondering what the 'best practice' is, when asking an event handler to unsubscribe its self after firing once. For context, this is my situation. A user is logged in, and is in a ready state to handle work items. They receive a work item, process it, then go back to ready again. At this point, they may want to say they're not avail...

Why can't I call BeginInvoke directly on a method rather than having to assign it to a delegate?

I'm just looking at some of my code and it occurred to me that given, Action<int> fireMessage = FireMessages; fireMessage.BeginInvoke(1, r => fireMessage.EndInvoke(r), null); As I can directly assign a method to a delegate, why can't I just call BeginInvoke on the method directly. The way this code reads suggests that t...

Extension methods on an interface; delegates

I'm trying to get around dual inheritance in C# by re-implementing one of the parent classes as an interface with extension methods. The problem I'm encountering is that event EventHandler<EventArgs> Disconnecting; public static void OnDisconnected(this AutoConnectClientBase target) { target.ClientConnectionStat...

associating TapDetectingView UIView subclass with UIView object created in IB?

I know this must seem like an extremely basic question for most iphone devs, but so far have been putting all my code logic into a single view controller, and want to start making better use of delegates, breaking up my code into logical components. I have a simple ViewController based application and want to add tap detection. There is...

Memory management with delegates?

Memory management with delegates, it is my understanding that I don't retain delegates, I am a little unsure about what to do with the delegate if the view gets unloaded (via viewDidUnload) and later recreated (via viewDidLoad)? @property(assign) SomeClass *someDelegate; . - (void)viewDidLoad { [super viewDidLoad]; someDelega...

How can I refactor our the type parameter from this code?

I want to write an extension method that tests if an attribute is applied on a method call, and I'd like to specify the method as a lambda expression. Currently, I have the following (working) approach, but I really don't like the way this code looks: // Signature of my extension method: public static bool HasAttribute<TAttribute, TDele...