Share via


TaskList.InvokeMethod(String, Object) Method

Definition

Calls the specified method.

public:
 virtual System::Object ^ InvokeMethod(System::String ^ methodName, System::Object ^ userData);
public virtual object InvokeMethod (string methodName, object userData);
abstract member InvokeMethod : string * obj -> obj
override this.InvokeMethod : string * obj -> obj
Public Overridable Function InvokeMethod (methodName As String, userData As Object) As Object

Parameters

methodName
String

The name of the method to call.

userData
Object

An arbitrary user-supplied object.

Returns

A user-defined object.

Examples

public override object InvokeMethod(string methodName, object userData)
{
    Type taskListType = GetType();

    MethodInfo methodInfo = taskListType.GetMethod(methodName);
    if (methodInfo != null)
    {
        if (userData == null)
        {
            return methodInfo.Invoke(this, null);
        } else
        {
            return methodInfo.Invoke(this, new object[] { userData });
        }
    } else
    {
        throw new InvalidOperationException("methodName : " + methodName +
            "\n taskListType.Name " + taskListType.Name);
    }
}

/// GetTaskItems() is called every time the context menu is invoked.
public override System.Collections.ICollection GetTaskItems() {

    ArrayList items = new ArrayList();

    Image imgAsk = rLoadImg.loadImgs(SystemIcons.Asterisk, 16);
    Image imgErr = rLoadImg.loadImgs(SystemIcons.Error, 16);

    items.Add(new MethodTaskItem(
                "DisplayTime",       // Method Name
                "Show Time",        // Menu item Text
                "DemoCategory")    // Category
                );

    Person prs = new Person(66, "Joe", "Smith");
    MethodTaskItem mti_i = new MethodTaskItem(
                                    "InvTst",       // Method Name
                                    "Invoke Test",   // Menu item Text
                                    sDemoCat,       // Category
                                    "Tool Tip:SC",  // ToolTip non-functional
                                    imgAsk,          // Menu Icon
                                    prs);      // user data
    mti_i.CausesNavigation = false;
    traceMTI(mti_i);

    items.Add(mti_i);


    items.Add(new MethodTaskItem(
          "ShowCnt",       // Method Name
          "Show Count",   // Menu item Text
          sDemoCat,       // Category
          "Tool Tip:SC",  // ToolTip non-functional
          mti_i.Image)    // Menu Icon
          );

public void myInvoke()
{
    TaskList tl = getMyTaskList();
    Person p = new Person(49, "Joe", "Smith");
    tl.InvokeMethod("InvTst", p);
}
// DemoHierarchyInfo.InvTst()
//
public int InvTst(Person p)
{
    Trace.WriteLine(" InvTst : person age: " + p._age.ToString()
    + "\n First name \"" + p._fName
    + "\"\n Last name " + p._LstName + "\"");

    return SH._pCnt;
}
// method DemoHierarchyInfo.HierarchyDemoInfoTaskList.InvTst()
public void InvTst(object obj)
{
    // Call parents InvTst (DemoHierarchyInfo.InvTst )
    //
    _owner.InvTst((Person)obj);
    UpdateCurPers();
    _owner.flush();
}

Remarks

A non-null userData parameter is valid only if you created the method task item by using the six-parameter MethodTaskItem constructor when you built the TaskList.

Applies to