I would like to get the name of the method that is being delegated as a Func.
Func<MyObject, object> func = x => x.DoSomeMethod();
string name = ExtractMethodName(func); // should equal "DoSomeMethod"
How can I achieve this?
-- For bragging rights --
Make ExtractMethodName also work with a property invocation, having it return the p...
I have a dialog based application in which I will delegating the I/O operation read write to different thread.
I just want to clear is there any difference between two approaches..
First approach: ( I am doing this in ,my main form -Form.cs)
delegate void Action();
Action _action = new Action(Method);
this.BeginInvoke(_action);
Seco...
In many situations, such as making the keyboard go away when the use clicks done, there are two options: set the text field's delegate to self, and adopt the UITextFieldDelegate protocol, and then use the method - (BOOL)textFieldShouldReturn:(UITextField *)textField; to resignFirstResponder and return YES. But you can also addTarget:self...
Hello,
I have a function Process(data, f) where data is a normal parameter and f is a function needed to process the data (passed as a delegate to Process)
The signature of f is int f(a,b,c), with a, b, c supplied by Process when it calls the delegate.
Up until here, standard delegate usage.
Now, I have a special but common case wher...
Hello!
I've a question about a good way to protect a bit my cocoa app from piracy!
I know that this is impossible!
So, in my app I've an isRegistered() method that run every time the user launch the app!
This is called in the applicationDidFinishLaunching: App delegate ... so if this method return true, the app continue to execute the ...
Is there a way to assign some sort of delegate object when
[[NSData alloc] initWithContentsOfUrl:... options:... errorPtr:...]
is called so that I can monitor percentage complete of a download or is the best way to handle this sort of thing through the use of the asynchronous NSURLConnection stuff?
...
Hi All,
I had a quick question. Something seems really wrong with this code. I want to take advantage of generics and delegates and quite possibly generic delegates if applicable. I am working with some code generated api's and the objects generated are very similiar. I see that they all implement an interface so I was to try to create o...
I'm sure that i'm just not understanding something fundamental about events and/or delegates in C#, but why can't i do the Boolean tests in this code sample:
public class UseSomeEventBase {
public delegate void SomeEventHandler(object sender, EventArgs e);
public event SomeEventHandler SomeEvent;
protected void OnSomeEvent(E...
I know a lot of the uses of .Net delegates can be emulated in Java by using a combination of interfaces and anonymous classes, but are there any situations where delegates have a real advantage and there is no Java equivalent?
...
Hi
I recently started digging into C# but I can't by my life figure out how delegates work when implementing the observer/observable pattern in the language.
Could someone give me a super-simple example of how it is done? I have googled this, but all of the examples I found were either too problem-specific or too "bloated".
...
Is it possible to override ONLY CERTAIN functions from an exisiting delegate, without ourself being a delegate totally?
I tried replacing the target IMP with mine, didn't work :'(
More detail:
+[SomeClass sharedDelegate]
-[sharedDelegate targetMethodToBeOverridden:Arg:] //OUR method needs to be called, not this
Method *targetMetho...
So I'm trying to do this exercise where I need to set a delegate for the main window. The purpose is to make sure that when the user resizes the window, it's always twice as wide as it is high.
This is my AppController.h file:
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject
{
NSWindow *windowWillResize;
}
@end
and t...
I am trying to use a separate delegate class (as many examples do) to perform the drawing of a large image in a CATiledlayer. The tiled layer has been added as a sub layer in a separate view. I first start out with a view controller.
// ImageInTiledLayerViewController.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import...
If I create CLLocationManager, assign it's delegate, and finally tell it to start updating, exactly which thread is calling the delegate? Some system thread?
...
I'm working on a CRUD testing class because I got tired of duplicating the same test patterns when validating my NHibernate mappings.
I've refactored the code and have reached the point where everything is working the way I envisioned it with one glaring irritation. Everything is based on strings which are used by reflection methods t...
I'm not sure about my terminology here, but:
I have a ViewController in an iPhone app that needs to be a delegate for two other objects (delegators).
Is this possible? This does not work:
@interface my_projectViewController : UIViewController <DelegatorOne> <DelegatorTwo> {
...
}
...
I have a maintenance application that has to turn enterprise data (from various databases/tables) into flat files, each in a specific format, for consumption by a legacy application. I've got data models like
public class StatusCode
{
public String Id { get; set; }
public Char Level { get; set; }
public String Description { ...
Consider the following code:
if (IsDebuggingEnabled) {
instance.Log(GetDetailedDebugInfo());
}
GetDetailedDebugInfo() may be an expensive method, so we only want to call it if we're running in debug mode.
Now, the cleaner alternative is to code something like this:
instance.Log(() => GetDetailedDebugInfo());
Where .Log() is d...
I have to send many web service calls out to delete a bunch of records in Amazon SDB (unfortunately, rows can only be deleted one at at time currently).
I am using Amazon's SDB c# library which does not use async WebRequests.
Currently I use ThreadPool.QueueUserWorkItem to queue up a bunch of calls (I configured my connectionManagement...
Hello,
Normally I setup events like this...
Public Delegate Sub MySpecialEventHandler(sender as object, e as mySpecialEventEventArgs) ' ...I will not show the implementation of mySpecialEventArgs.
Public Event MySpecialEvent as MySpecialEventHandler
Private Sub OnMySpecialEvent(newStatus as string)
Raise Event MySpecialEv...