delegates

Registering a delegate function with an ISO C++ callback (on mono)

I am exposing some ISO C++ data types to .Net (mono on Linux to be precise). For the purpose of brevity, I shall refer to C# in my question, although my question relates to all of the .Net languages (with C# and VB.Net being my target languages). So far, I have worked out how to expose the ISO C++ data types in C# class(es) for use in...

How can I use delegates to call styling methods?

I need to style a ton of different elements (read: "cells") in a PDF using iTextSharp. Label, header, subheader, number, etc. Right now, I'm using three different methods for each cell type: public static PdfPCell GetDefaultCell(string strText) { PdfPCell cell = new PdfPCell(new Phrase(strText, GetDefaultFont())); ce...

How to defer execution of an Event on each item in a collection until iteration of collection is complete using delegates and/or events?

Of Note: This is more of a curiosity question than anything else. Given a List<Window> where each window has an event attached to the Close Event which removes the window from the collection, how could you use delegates / events to defer the execution of the Close Event until the collection has been iterated? For example: public class...

C# Delegate Invoke Required Issue

Scenario I have a C# windows forms application that has a number of processes. These processes run on separate threads and all communicate back to the Main Form class with updates to a log window and a progress bar. I'm using the following code below, which up until now has worked fine, however, I have a few questions. Code deleg...

Create a delegate from a property getter or setter method

To create a delegate from a method you can use the compile type-safe syntax: private int Method() { ... } // and create the delegate to Method... Func<int> d = Method; A property is a wrapper around a getter and setter method, and I want to create a delegate to a property getter method. Something like public int Prop { get; set; } ...

Verify method with Delegate parameter in Moq

Using Moq for generation of Stubs and Mocks in my unit tests, I have a case where I want to Verify that a method that takes a Delegate parameter is called. I don't care about the particular Delegate parameter supplied I just want to make sure that the method is in fact called. The method looks like this: public interface IInvokerProxy{ ...

How set EnqueueCallBack to my generic callback

using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsistec.Domain; using Microsistec.Client; using Microsoft.VisualStudio.TestTools....

How to use delegate to perform callback between caller and web service helper class?

I have 2 classes A and B, where they belongs to the same namespace but resides in seperate files namely a.cs and b.cs, where class B essentially is a helper wrapping a web service call as follow: public class A { public A() // constructor { protected static B b = new B(); } private void processResult1(string res...

Can we have Same Delegate for Two Events

Can we have same delegate for two events ? which have same number of input parameters? or delegate and the events have one to one relation ? ...

Callbacks in C#

I started coding in C# and have never had the opportunity to use callbacks though I have used delegates for event wiring. What is the real application of callbacks. I would be grateful if you could give some link that explains about callbacks in a straight forward way without C++ prerequisites. ...

Using a delegate to populate a listbox

Ive been playing around with delegates trying to learn and I ran into one small problem Im hoping you can help me with. class myClass { OtherClass otherClass = new OtherClass(); // Needs Parameter otherClass.SendSomeText(myString); } class OtherClass { public delegate void TextToBox(string s); TextToBox textToBox; publ...

Why not .NET-style delegates rather than closures in Java?

OK, this is going to be my beating a dying horse for the 3rd time. However, this question is different from my earlier two about closures/delegates, which asks about plans for delegates and what are the projected specs and implementation for closures. This question is about - why is the Java community struggling to define 3 different t...

Was delegates static by default?

Hello All, I was just trying to understand delegates using the following code. public class delegatesEx { public delegate int Mydelegate(int first, int second); public int add(int first, int second) { return first + second; } public int sub(int first, int second) { return first - second; } }...

UITableView delegate method called twice

Hello everybody, Today my question is about UITableViewController-s In particular I have noticed that the datasource delegate method - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; is called twice (even if for instance I just create a navigation based application and without adding a line of code.. well adding an N...

Need an explanation on this code - c#

I am getting familiar with C# day by day and I came across this piece of code public static void CopyStreamToStream( Stream source, Stream destination, Action<Stream,Stream,Exception> completed) { byte[] buffer = new byte[0x1000]; AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(null); Action<Exception> done = e => { ...

Accessing ViewController's variables from UIActionSheet delegate

Hello. I have the following code: @implementation SendMapViewController NSMutableArray *emails; At this method I create emails array and I add some NSStrings: - (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson: (ABRecordRef)person { ABMultiVal...

Logging class using delegates (NullReferenceException)

I have created a small application but I would now like to incorporate some type of logging that can be viewed via listbox. The source of the data can be sent from any number of places. I have created a new logging class that will pass in a delegate. I think Im close to a solution but Im receiving a NullReferenceException and I don’t...

Delegates and ParamArray - Workaround Suggestions?

Some predefined methods contain a ParamArray in their signature. Delegates, however, cannot contain a ParamArray in their signature. Question: Assume you wish to create a delegation mechanism for a specific method which requires a ParamArray. How would you work around this constraint? EDIT: just to make clear, assume you cannot change ...

jquery ui autocomplete with delegate

I have set up JQuery UI autocomplete according to the docs and it works for any input with class="tag-item" that is rendered to the page. However the user can add inputs into the dom via JS so I need a way to bind autocomplete to the new dynamically created inputs using delegate. I am not sure how to set this up, any ideas would be appre...

LINQ to SQL: Reusable expression for property?

Pardon me for being unable to phrase the title more exact. Basically, I have three LINQ objects linked to tables. One is Product, the other is Company and the last is a mapping table Mapping to store what Company sells which products and by which ID this Company refers to this Product. I am now retrieving a list of products as follows:...