delegates

ASP.NET Event delegation between user controls

Give the following control hierarchy on a ASP.NET page: Page HeaderControl       (User Control) TitleControl       (Server Control) TabsControl       (User Control) other controls I'm trying to raise an event (or some notification) in the TitleControl that bubbles to the Page level. Then, I'd like to (optionally) register an even...

Problem using delegates, static, and dependencyproperties

I'm trying to animate a private variable named radius, which works. However while its changing I'm trying to execute a function which is getting to be quite of a problem. the code i have is below, it wont run because it has the following error An object reference is required for the non-static field, method, or property 'AppPart.SetChil...

C# - class field is null when accessed from a worker thread but not main thread

Not sure what I'm doing wrong: class MyClass { private EventInfo eventInfo; public void OnGenerateEvent(object sender, EventArgs e) { // Called from *main* thread // Load assembly and set eventInfo here eventInfo = ....GetEvent(...); eventInfo.AddEventHandler(source, handler); //...

How I pass a delegate prototype to a method?

SO lets say in my class I have: public delegate bool MyFunc(int param); How can I then do this someObj.PassMeADelegateToExamine(this.MyFunc); // not possible!?! SO that I can examine the delegate and perhaps use reflection or something idk to find out it's return type and any params it might have? Basically if I can transform it i...

Translating delegate usage from C# to VB

In physics library written in C# I have the following code: (in ContactManager.cs) public delegate void PostSolveDelegate(Contact contact, ref ContactImpulse impulse); public PostSolveDelegate PostSolve; And an example that uses that code is: (in Test.cs) public virtual void PostSolve(Contact contact, ref ContactImpulse impulse) { ...

Event handling C# / Registering a callback

Events can only return void and recieve object sender/eventargs right? If so then craptastic.... how can I pass a function pointer to another obj, like: public bool ACallBackFunc(int n) { return n > 0; } public void RegisterCallback(Something s) { s.GiveCallBack(this.ACallBackFunc); } Something::GiveCallBack(Action? funcPtr...

How to pass event to method?

I would like to create a method that takes as a argument an event an adds eventHandler to it to handle it properly. Like this: I have 2 events: public event EventHandler Click; public event EventHandler Click2; Now i would like to pass particular event to my method like this (pseudocode): public AttachToHandleEvent(EventHandler MyEv...

C# event or delegate or other solution?

Looking for some help or programmng ideas or mayeb there is some pattern that would help. Have an application that needs to fire alot of events sequentially, it could up to 100 or more unique events, it will be dynamic depeneding on the situation. Trying to find the best practice for doing this. My main idea right now is to create a li...

Unit testing that an event is raised in C#, using reflection

I want to test that setting a certain property (or more generally, executing some code) raises a certain event on my object. In that respect my problem is similar to http://stackoverflow.com/questions/248989/unit-testing-that-an-event-is-raised-in-c, but I need a lot of these tests and I hate boilerplate. So I'm looking for a more genera...

Problem with anonymouse delegate within foreach

public Form1() { InitializeComponent(); Collection<Test> tests = new Collection<Test>(); tests.Add(new Test("test1")); tests.Add(new Test("test2")); foreach (Test test in tests) { Button button = new Button(); button.Text = test.name; button.Click...

UITableView crashes when trying to scroll

Hi, I have a problem with data in UITableView. I have UIViewController, that contains UITableView outlet and few more things I am using and ... It works :) ... it works lovely, but ... I've created an RSS reader class that is using delegates to deploy the data to the table ... and once again, If I'll just create dummy data in the main ...

(Action<T>).Name does not return expected values

I have the following method (used to generate friendly error messages in unit tests): protected string MethodName<TTestedType>(Action<TTestedType> call) { return string.Format("{0}.{1}", typeof(TTestedType).FullName, call.Method.Name); } But when I call it as follows, I don't get the expected results: var nm = MethodName<MyContro...

The Main Purpose of Events in C#

I've been examining one of my c# books and I just saw a sentence about Events in C#:  The main purpose of events is to prevent subscribers from interfering with each other. Whatever it means, yeah actually events are working pretty much like delegates. I've been wondering why I should use events instead of delegates. So is there any o...

Namespace scoped aliases for generic types in C#

Let's have a following example: public class X { } public class Y { } public class Z { } public delegate IDictionary<Y, IList<Z>> Bar(IList<X> x, int i); public interface IFoo { // ... Bar Bar { get; } } public class Foo : IFoo { // ... public Bar Bar { get { return null; //... ...

.delegate equivalent of an existing .hover method in jQuery 1.4.2

I have an event handler bound to the hover event using the .hover method, which is below: $(".nav li").hover(function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); }); It is important to note, that I require both functions within the handler to ensure synchronisation. Is it possible to rewrite ...

How do I invoke a MethodInfo that was created from an anonymous method?

In a previous question, I asked how to get a MethodInfo from an Action delegate. This Action delegate was created anonymously (from a Lambda). The problem I'm having now is that I can't invoke the MethodInfo, because it requires an object to which the MethodInfo belongs. In this case, since the delegates are anonymous, there is no own...

asp.net vb user control raising an event on the calling page

i'm trying to learn about user controls. I created a user control that has a textbox and a button. What i'd like to be able to do is when i click the button in the user control, populate a label in the aspx page. I understand that i could just have a button on the page that uses some properties on the user control to get that informa...

C#: Delegate syntax?

I'm developing a game. I want to have game entities each have their own Damage() function. When called, they will calculate how much damage they want to do: public class CombatantGameModel : GameObjectModel { public int Health { get; set; } /// <summary> /// If the attack hits, how much damage does it do? /// </summary>...

Get compiler generated delegate for an event

I need to know what handlers are subsribed to the CollectionChanged event of the ObservableCollection class. The only solution I found would be to use Delegate.GetInvocationList() on the delegate of the event. The problem is, I can't get Reflection to find the compiler generated delegate. AFAIK the delegate has the same name as the event...

Func<T> injecting with Windsor container

Here is a code excerpt from AspComet project that works with Autofac. public MessageBus(IClientRepository clientRepository, Func<IMessagesProcessor> messagesProcessorFactoryMethod) { this.clientRepository = clientRepository; this.messagesProcessorFactoryMethod = messagesProcessorFactoryMethod; } How can I inject "Func<IMessage...