Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

MethodInvoker Class

Helper class allowing one to declaratively specify a method call for later invocation.

For a list of all members of this type, see MethodInvoker Members .

System.Object
   MethodInvoker
      ArgumentConvertingMethodInvoker

[Visual Basic]
Public Class MethodInvoker
[C#]
public class MethodInvoker

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

Typically not used directly but via its subclasses such as MethodInvokingFactoryObject.

Usage: specify either the TargetType and TargetMethod or the TargetObject and TargetMethod properties respectively, and (optionally) any arguments to the method. Then call the Prepare method to prepare the invoker. Once prepared, the invoker can be invoked any number of times.

Example

The following example uses the MethodInvoker class to invoke the ToString() method on the Foo class using a mixture of both named and unnamed arguments.

public class Foo 
{
    public string ToString(string name, int age, string address)
    {
        return string.Format("{0}, {1} years old, {2}", name, age, address);
    }
    
    public static void Main()
    {
        Foo foo = new Foo();
        MethodInvoker invoker = new MethodInvoker();
        invoker.Arguments = new object [] {"Kaneda", "18 Kaosu Gardens, Nakatani Drive, Okinanawa"};
        invoker.AddNamedArgument("age", 29);
        invoker.Prepare();
        // at this point, the arguments that will be passed to the method invocation
        // will have been resolved into the following ordered array : {"Kaneda", 29, "18 Kaosu Gardens, Nakatani Drive, Okinanawa"}
        string details = (string) invoker.Invoke();
        Console.WriteLine (details);
        // will print out 'Kaneda, 29 years old, 18 Kaosu Gardens, Nakatani Drive, Okinanawa'
    }
}

Requirements

Namespace: Spring.Objects.Support

Assembly: Spring.Core (in Spring.Core.dll)

See Also

MethodInvoker Members | Spring.Objects.Support Namespace