delegates

Covariance, Contravariance and Delegate Problem

Hi there, I again need help by you, this time I struggle with covariance, contravariance, delegates and an simple idea blowing up... I want to implement an attribute for our businessobject-properties that takes a delegate and the needed parameters for that one, so that I can work with reflection, read out the attribute and perform a va...

iPhone - Several UIAlertViews for a delegate

Currently I've got a class popping up UIAlertViews here and there. Currently, the same class is the delegate for these (it's very logical that it would be). Unfortunately, these UIAlertViews will call the same delegate methods of the class. Now, the question is - how do you know from which alert view a delegate method is invoked? I was t...

C# - Declaration of types within a namespace

Hi folks, what could be a possible use of declaring types within a namespace but not in a class. For ex: namespace Test { public delegate void Ispossible(); } This is valid & does not generate any compilation errors but i can't think of why we would declare it this way as opposed to inside a class. ...

Delegate Covariance Confusion Conundrum!

Why does this not work? Do I not understand delegate covariance correctly? public delegate void MyDelegate(object obj) public class MyClass { public MyClass() { //Error: Expected method with 'void MyDelegate(object)' signature _delegate = MyMethod; } private MyDelegate _delegate; public void MyMe...

Proper naming convention for a .NET Delegate type?

By convention classes are often named like nouns, methods like verbs and interfaces like adjectives. What is the common naming convention for a delegate? Or what's a good way to differentiate its name when delegates are listed among types and other things? My immediate assumption is to name a delegate more like an adjective because a ...

Should I convert PropertyInfo.SetProperty() into MethodInfos for execution

I was just reading http://stackoverflow.com/questions/25458/how-costly-is-reflection-really I do numerous reflection calls for property sets and was wondering if I should be looking at converting all of my PropertyInfo.SetProperty() into MethodInfos calls so that I can run Delegate.CreateDelegate against. Finally if I do this, I assume ...

finding the Delegate Method registered to an Event

Hello Assuming I have an event subscription such as _vm.PropertyChanged += OnViewModelAmountChanged; How can I see that method name by reflection the way you can see it in the debugger? I got as far as the line below before I decided I might be in the Twilight Zone ?vm.GetType().GetEvent("PropertyChanged").EventHandlerType.GetMethod...

Why doesn’t BeginInvoke return reference of type AsyncResult?

When you call a delegate object’s BeginInvoke, the system creates an object of type AsyncResult, but BeginInvoke returns a reference of type IAsyncResult interface ( which points to AsyncResult instance) . Why doesn’t BeginInvoke instead return a reference of type AsyncResult? thanx ...

When should asynchronous delegates use a Callback pattern?

One of the patterns used with asynchronous delegates is also a Callback pattern, where initial thread ( one that called BeginInvoke ) T1 continues without waiting or checking whether the spawned thread T2 has completed. Instead, when T2 has completed, the T2 calls callback method, which handles the results, calls EndInvoke and informs t...

c# Emitting Dynamic Method Delegate to Load Parametrized Constructor Problem

I am trying create a delegate representation of constructor by emitting a Dynamic Method, which has to match this very "loosely-typed" signature so it can be used with any kind of parametrized constructor: public delegate Object ParamsConstructorDelegate(params object[] parameters); and the code for this creating the delegate looks li...

Running multiple delegates asynchronously and waiting for response in C#

Hi, I have a table of urls which I need to loop through, download each file, update the table and return the results. I want to run up to 10 downloads at a time so am thinking about using delegates as follows: DataTable photos; bool scanning = false, complete = false; int rowCount = 0; public delegate int downloadFileDelegate(); p...

How can I emit a call to a delegate whose type is unfinished at the time of the emit?

Hi everyone. I'm having trouble emitting a call to a delegate whose type is unfinished at the time of the emit. I'll elaborate: I've declared the following delegate type: // Delegate type. The 'firstArgument' will be 'this', i.e., this is an open // instance method: the implicit argument is here given explicitly, in // 'firstArgument'. ...

Linq where keyword vs. Where extension and Expression parameters

Hi, Passing in an Expression to a Linq query behaves differently depending on syntax used, and I wonder why this is the case. Let's say I have this very generic function private IEnumerable<Company> GetCompanies(Expression<Func<Company, bool>> whereClause) The following implementation works as expected private IEnumerable<Comp...

Modal Views and Delegation

Currently I'm working on an iPhone app that asks the user for login information, verifies this information and presents the user with a table view of their information. On launch the application delegate launches an empty table view along with the modal view to ask for login credentials. The login credentials consist of a standard us...

Memory Leak in Application Main()

The following code is producing a memory leak on the in retVal line: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; Any ideas on how to fix? ...

What is the proper way to access local variables in a delegate?

I'm trying to access an NSMutableArray which is a data member of my AppDelegate class. It is synthesized in the implementation, and is an array of a custom class which has a "name" NSString data member. I currently use it to fill a Table View (a SubView) like this: cell.textLabel.text = [[[delegate contentArray] objectAtIndex:indexPat...

What thread are iphone delegate methods run in for webview and core location callbacks?

I have an issue that looks like a race condition with a webview callback and a location manager callback that interact with the same variables and an alert dialog - the dialog is created in the location callback and should be dismissed in the webview callback. I thought that the delegate callbacks for standard objects like the webview a...

Passing delegate with return type other than void in thread

I want to pass a delegate with the return type as ArrayList as parameter of thread and want to store the values in an ArrayList as well. Any help in this regard will be appreciated. ...

Using MethodInvoker in a backend class

I have a backend class that has to raise an event with no arguments. The MethodInvoker has the desired signature but it feels a little odd to use it in a backend class since it is defined in System.Windows.Forms. Is there another delegate with this signature in other namespaces in the .Net Framework? If not, do you think that I should de...

Calculate total content length of HttpFileCollection using Lambda expressions

My code has something like this: HttpFileCollection files Instead of looping through each file and adding up the file.ContentLength to get the total length of all content e.g. int totalLength = 0; for (int i = 0; i < files.Count; i++) { totalLength += files[i].ContentLength; } Is there a ...