Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting target of Action

I have created the fallowing Sample-Code:

class Program {
    static void Main(string[] args) {
        var x = new ActionTestClass();
        x.ActionTest();
        var y = x.Act.Target;
    }
}

public class ActionTestClass {
    public Action Act;
    public void ActionTest() {
        this.Act = new Action(this.ActionMethod);
    }

    private void ActionMethod() {
        MessageBox.Show("This is a test.");
    }
}

When I do this on this way, y will an object of type ActionTestClass (which is created for x). Now, when I change the line

this.Act = new Action(this.ActionMethod);

to

this.Act = new Action(() => MessageBox.Show("This is a test."));

y (the Target of the Action) will be null. Is there a way, that I can get the Target (in the sample the ActionTestClass-object) also on the way I use an Anonymous Action?

like image 928
BennoDual Avatar asked Nov 28 '11 15:11

BennoDual


People also ask

What is the difference between a target and an action?

action is where the data is sent, target is which window (or tab, frame, iframe) to use for the request. If action is omitted, it assumed to be the current page (the same URL). If target is omitted, it is assumed to be the same window (or tab).

What is target _blank in HTML?

Description. _blank. Opens the linked document in a new window or tab. _self. Opens the linked document in the same frame as it was clicked (this is default)

What is the name of a property that identifies the receiver of action messages?

The Target A target is a receiver of an action message.


1 Answers

The lack of Target (iow == null) implies the delegate is either calling a static method or no environment has been captured (iow not a closure, just a 'function pointer').

like image 154
leppie Avatar answered Sep 21 '22 06:09

leppie