delegates

Call parent function in xcode iphone development

We have 2 files 'MainViewController' and 'View01' The first file addSubView the second one. In the first file we have a function named displayView. I want to be able to call this function from the View01 file is the following code correct part of View01 file #import "MainViewController.h" - (IBAction) changeView:id(sender){ Ma...

Add delegate or event property to this class?

I created a control where other developers can create an instance and use. There is a button click in the control. How do I allow developers to plug in their own code in a certain part of my control? I am not sure if or how exactly to use a delegate or event in this scenario. Can someone help in the below example: public class MyControl...

Enforcing implementation of events in derived abstract classes.

I am trying to create what I am thinking of as a translation class, so that my program can speak to a variety of target platforms. Each platform will be handled by a separate implementation of an abstract class. I have pared things down for the sake of simplicity. I have an abstract class, with a couple of abstract methods: abstract cl...

Delegate of UIScrollView / Subviews

hi, can you help me setting up a delegate for a UIScrollView, so I can interact with it from within it's subviews? Following problem: I added some UIViewControllers (with extra nibs) to a UIScrollView. I want to control the ScrollView from within those subviews. E.g. I want to disable scrolling when I press a button. In another threa...

Error binding to target method in C#3.0

I am trying to hook Up a Delegate Using Reflection. This is what I have done so far using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Data; using System.Threading; using System.IO; using System.Reflection; using System.Windows; namespace ChartHelper { public class I...

Where does delegates' constructors and member functions are defined?

When I was looking at the Action delegates in Reflector, I saw it has a constructor like public Action(object @object, IntPtr method); But I could not find any body for the same along with other member functions like Invoke, BeginInvoke etc. I can only see the definitions for it. Where does these functions are defined? Are they define...

Delegates and variables scope

Hello all, I have the following code: public void SetMove(Position3D pos, float time, float linearity, bool relative) { ExecuteOnActiveClients(delegate(NeuroClient client) { client.Engine.GetProcAnimation(name).SetMove(pos, time, linearity, relative); ...

How to create a fully parameterized method delegate in C#?

In c# we can create delegates via a variety of means (e.g. Action<>, Func<>, delegate, lambdas, etc). But when you invoke those methods, you have to provide the parameter values for the delegate you are invoking: delegate int del(int i); del myDelegate = x => x * x; int j = myDelegate(5); Is there a way in c# to encapsulate a meth...

C#: Altering values for every item in an array

I'm wondering if there is built-in .NET functionality to change each value in an array based on the result of a provided delegate. For example, if I had an array {1,2,3} and a delegate that returns the square of each value, I would like to be able to run a method that takes the array and delegate, and returns {1,4,9}. Does anything lik...

Polymorphic delegates

C# chokes on delegate void Bar<T>(T t); void foo(Bar bar) { bar.Invoke("hello"); bar.Invoke(42); } The workaround is to use an interface interface Bar { void Invoke<T>(T t); } but now I need to go out of my way to define the implementations of the interface. Can I achieve the same thing with delegates and simple metho...

Using Delegates to Pass Information back to UI from custom socket class

All I am in the process of prototyping a small sockets application, which monitors IT infrastructure (due to in-house financial and deployment restrictions, I am unable to utilise an existing commercial or open-source solution). Basically, I have a server application and associated agent process for communicating heart-beat data to the...

How to create an algorithm type?

Say I have two sequences of numbers, A and B. How can I create an object to describe the relationship between the two sequences? For example: A: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9... B: 0, 2, 4, 6, 8, 10, 12, 14, 16, 18... B = 2A The relationship, f() is how we get from A to B. But given two arbitrary sequences, how can I construct...

Discrete Anonymous methods sharing a class?

I was playing a bit with Eric Lippert's Ref<T> class from here. I noticed in the IL that it looked like both anonymous methods were using the same generated class, even though that meant the class had an extra variable. While using only one new class definition seems somewhat reasonable, it strikes me as very odd that only one instance...

What's the difference between .delegate() and live()?

Since $("table").delegate("td", "hover", function(){ $(this).toggleClass("hover"); }); Is equivalent to the following code written using .live(): $("table").each(function(){ $("td", this).live("hover", function(){ $(this).toggleClass("hover"); }); }); according to jQuery API. I bet I'm wrong but isn't it the s...

MethodInfo and Delegates

I am using dotnet 2.0 I know that with an EventInfo value, you can loop through an Assembly's Types and find all the methods that match the EventInfo delegate definition ( EventInfo.EventHandlerType ) Is there a way to find out what available delegates a given MethodInfo can be assigned in the Delegate.CreateDelegate() function without...

Difference between different ways to invoke a delegate

What is the difference between the following? public delegate void SetSthDelegate(int[] x); // 1) SetSthDelegate sst = new SetSthDelegate(SetSthMethod); sst(x); // 2) Invoke(new SetSthDelegate(SetSthMethod), new object[] {x} // 3) BeginInvoke(new SetSthDelegate(SetSthMethod), new object[] {x} I learned that 2) is for invoking metho...

Sort list by property/anonymous function?

I've got a list defined like this... var sets = new List<HashSet<int>>(numSets); Why isn't there an overload so I can sort it like this? sets.Sort(s => s.Count); I want the largest set first. What's the easiest way to do that? ...

What is the difference between delegates in C# and functions as first class values in F#?

More specifically what are the characteristics (if any) that delegates have that functions as first class values in F# don't have; and what are the characteristics that functions as first class values have (if any) that delegates in C# don't have? ...

Delegates/Anonymous Method in C# 2

In C# 1. You don't have delegate sorting or comparison options. You might be forced to do it by creating another type which implements IComparer to sort your collections in ArrayList. But starting from c# 2. You can use delegates for your comparisons. Look the following example. List<Product> products = Product.GetSampleProducts(); prod...

Implementing the Command Pattern using C# Action delegate

Is it possible implement the GOF command pattern using a Queue of Action delegates? I have been trying to wrap my head around it for a while and I am stumped because each of the possible actions I want to add to the queue may have a varing number of parameters. Any suggestions? Am I barking up the wrong tree by focusing on the command ...