Search Results for

    Show / Hide Table of Contents

    Class Invoker

    Static methods to dynamically invoke methods and access fields of an object.

    Inheritance
    Object
    Invoker
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Microsoft.ML.Probabilistic.Compiler.Reflection
    Assembly: Microsoft.ML.Probabilistic.Compiler.dll
    Syntax
    public static class Invoker

    Methods

    Clone(Object)

    Clone an object by reflection on its fields.

    Declaration
    public static object Clone(object o)
    Parameters
    Type Name Description
    Object o
    Returns
    Type Description
    Object

    Clone(Object, Boolean)

    Declaration
    public static object Clone(object o, bool cloneFields)
    Parameters
    Type Name Description
    Object o
    Boolean cloneFields
    Returns
    Type Description
    Object

    GenericParameterCount(MethodBase)

    Declaration
    public static int GenericParameterCount(MethodBase method)
    Parameters
    Type Name Description
    MethodBase method
    Returns
    Type Description
    Int32

    GenericParameterCount(Type)

    Declaration
    public static int GenericParameterCount(Type type)
    Parameters
    Type Name Description
    Type type
    Returns
    Type Description
    Int32

    GetBestMethod(MethodBase[], Type, Type[], ConversionOptions, out Binding, out Exception)

    Find the method which best matches the given arguments.

    Declaration
    public static MethodBase GetBestMethod(MethodBase[] methods, Type targetType, Type[] argTypes, ConversionOptions conversionOptions, out Binding binding, out Exception exception)
    Parameters
    Type Name Description
    MethodBase[] methods

    Methods to search through

    Type targetType

    The type of this, for instance methods. If looking for a static method, use null.

    Type[] argTypes

    Types. argTypes.Length == number of method parameters. argTypes[i] may be null to allow any type, or typeof(Nullable) to mean "any nullable type".

    ConversionOptions conversionOptions

    Specifies which conversions are allowed

    Binding binding

    Modified to contain the generic type arguments and argument conversions needed for calling the method

    Exception exception

    Exception created on failure

    Returns
    Type Description
    MethodBase

    A non-null MethodBase.

    Exceptions
    Type Condition
    ArgumentException

    The best matching type parameters did not satisfy the constraints of the generic method.

    MissingMethodException

    No match was found.

    GetBestMethod(MethodBase[], Type, Type[], out Exception)

    Find the method which best matches the given arguments.

    Declaration
    public static MethodBase GetBestMethod(MethodBase[] methods, Type targetType, Type[] argTypes, out Exception exception)
    Parameters
    Type Name Description
    MethodBase[] methods
    Type targetType

    The type of this, for instance methods. If looking for a static method, use null.

    Type[] argTypes

    Types. argTypes.Length == number of method parameters. argTypes[i] may be null to allow any type, or typeof(Nullable) to mean "any nullable type".

    Exception exception

    Exception created on failure

    Returns
    Type Description
    MethodBase

    A non-null MethodBase.

    Exceptions
    Type Condition
    ArgumentException

    The best matching type parameters did not satisfy the constraints of the generic method.

    MissingMethodException

    No match was found.

    GetBestMethod(Type, String, BindingFlags, Type, Type[], out Exception)

    Find the method which best matches the given arguments.

    Declaration
    public static MethodBase GetBestMethod(Type type, string memberName, BindingFlags flags, Type targetType, Type[] argTypes, out Exception exception)
    Parameters
    Type Name Description
    Type type
    String memberName
    BindingFlags flags
    Type targetType

    The type of this, for instance methods. If looking for a static method, use null.

    Type[] argTypes

    Types. argTypes.Length == number of method parameters. argTypes[i] may be null to allow any type, or typeof(Nullable) to mean "any nullable type".

    Exception exception

    Exception created on failure

    Returns
    Type Description
    MethodBase

    null on failure.

    Exceptions
    Type Condition
    ArgumentException

    The best matching type parameters did not satisfy the constraints of the generic method.

    MissingMethodException

    No match was found.

    GetLoadedType(String)

    Get a type by name.

    Declaration
    public static Type GetLoadedType(string typeName)
    Parameters
    Type Name Description
    String typeName

    The name of a type in the System library or any loaded assembly.

    Returns
    Type Description
    Type

    The Type object.

    GetParameterTypes(MethodBase)

    Declaration
    public static Type[] GetParameterTypes(MethodBase method)
    Parameters
    Type Name Description
    MethodBase method
    Returns
    Type Description
    Type[]

    GetTypeArray(Object[])

    Gets the types of the objects in the specified array.

    Declaration
    public static Type[] GetTypeArray(object[] args)
    Parameters
    Type Name Description
    Object[] args

    An array of objects whose types to determine. args[i] can be null, whose type is assumed to be typeof(Nullable).

    Returns
    Type Description
    Type[]

    An array of Type objects representing the types of the corresponding elements in args.

    Remarks

    This method is the same as Type.GetTypeArray except it allows null values.

    GetValue(Object, Object[])

    Get an element from an array or collection, or invoke a delegate.

    Declaration
    public static object GetValue(object target, params object[] args)
    Parameters
    Type Name Description
    Object target

    An array, collection, delegate, or method group.

    Object[] args

    Indices for the collection or arguments for the delegate. May be null.

    Returns
    Type Description
    Object

    The collection element or return value of the delegate. If args == null, the target itself.

    HasAttribute(MemberInfo, Type)

    Declaration
    public static bool HasAttribute(MemberInfo member, Type attributeType)
    Parameters
    Type Name Description
    MemberInfo member
    Type attributeType
    Returns
    Type Description
    Boolean

    Invoke(MethodBase, Object, Object[])

    Invoke a generic method by inferring type parameters from the method arguments.

    Declaration
    public static object Invoke(MethodBase method, object target, params object[] args)
    Parameters
    Type Name Description
    MethodBase method
    Object target
    Object[] args
    Returns
    Type Description
    Object

    Invoke(MethodBase[], Object, Object[])

    Invoke the method which best matches the argument types.

    Declaration
    public static object Invoke(MethodBase[] methods, object target, params object[] args)
    Parameters
    Type Name Description
    MethodBase[] methods

    A non-empty list of methods, exactly one of which will be invoked. Can include both static and instance methods.

    Object target

    The instance for an instance method, or if non-null, the first argument of a static method.

    Object[] args

    The remaining arguments of the method.

    Returns
    Type Description
    Object

    The return value of the method.

    InvokeInstance(String, Object, Object[])

    Invoke the instance member which best matches the argument types.

    Declaration
    public static object InvokeInstance(string methodName, object target, params object[] args)
    Parameters
    Type Name Description
    String methodName
    Object target
    Object[] args
    Returns
    Type Description
    Object

    InvokeMember(Type, String, BindingFlags, Object, Object[])

    Invoke the member which best matches the argument types.

    Declaration
    public static object InvokeMember(Type type, string memberName, BindingFlags flags, object target, params object[] args)
    Parameters
    Type Name Description
    Type type

    The type defining the member.

    String memberName

    The name of a field, property, event, instance method, or static method.

    BindingFlags flags
    Object target

    The object whose member to invoke. Ignored for a static field or property. If target is non-null, then it is provided as the first argument to a static method.

    Object[] args

    Can be empty or null. Empty means a function call with no arguments.
    null means get the member itself.

    Returns
    Type Description
    Object

    The result of the invocation. For SetField/SetProperty the result is null.

    Remarks

    This routine is patterned after Type.InvokeMember. flags must specify Instance, Static, or both.

    If flags contains CreateInstance, then name is ignored and a constructor is invoked.

    If memberName names a field/property and flags contains SetField/SetProperty, then the field/property's value is changed to args[args.Length-1]. If args.Length > 1, the field/property is indexed by args[0:(args.Length-2)].

    If memberName names a field/property and flags contains GetField/GetProperty, then the field/property's value is returned. If args != null and the field/property is a delegate, then it is invoked with args. Otherwise if args != null, the field/property is indexed by args.

    If memberName names an event and flags contains GetField, then the event's EventInfo is returned. If args != null, then the event is raised with args.

    If memberName names a method and flags contains InvokeMethod, then it is invoked with args. A static method is invoked with target and args. If args == null, then the result is a DelegateGroup containing all overloads of the method.

    Other flag values are implemented as in Type.InvokeMember. In each case, overloading is resolved by matching the argument types, possibly with conversions.

    If a matching member is not found, the interfaces of the type are also searched. As a last resort, if the memberName is op_Equality or op_Inequality, then a default implementation is provided (as in C#).

    Exceptions
    Type Condition
    MissingMemberException
    ArgumentException

    InvokeStatic(Type, String, Object[])

    Invoke the static member which best matches the argument types.

    Declaration
    public static object InvokeStatic(Type type, string methodName, params object[] args)
    Parameters
    Type Name Description
    Type type
    String methodName
    Object[] args
    Returns
    Type Description
    Object

    op_Addition(Int32, Int32)

    Declaration
    public static int op_Addition(int a, int b)
    Parameters
    Type Name Description
    Int32 a
    Int32 b
    Returns
    Type Description
    Int32

    op_BooleanAnd(Boolean, Boolean)

    Declaration
    public static bool op_BooleanAnd(bool a, bool b)
    Parameters
    Type Name Description
    Boolean a
    Boolean b
    Returns
    Type Description
    Boolean

    op_BooleanNot(Boolean)

    Declaration
    public static bool op_BooleanNot(bool b)
    Parameters
    Type Name Description
    Boolean b
    Returns
    Type Description
    Boolean

    op_BooleanOr(Boolean, Boolean)

    Declaration
    public static bool op_BooleanOr(bool a, bool b)
    Parameters
    Type Name Description
    Boolean a
    Boolean b
    Returns
    Type Description
    Boolean

    op_Equality(Object, Object)

    Declaration
    public static bool op_Equality(object a, object b)
    Parameters
    Type Name Description
    Object a
    Object b
    Returns
    Type Description
    Boolean

    op_GreaterThan(Int32, Int32)

    Declaration
    public static bool op_GreaterThan(int a, int b)
    Parameters
    Type Name Description
    Int32 a
    Int32 b
    Returns
    Type Description
    Boolean

    op_GreaterThanOrEqual(Int32, Int32)

    Declaration
    public static bool op_GreaterThanOrEqual(int a, int b)
    Parameters
    Type Name Description
    Int32 a
    Int32 b
    Returns
    Type Description
    Boolean

    op_Inequality(Object, Object)

    Declaration
    public static bool op_Inequality(object a, object b)
    Parameters
    Type Name Description
    Object a
    Object b
    Returns
    Type Description
    Boolean

    op_LessThan(Int32, Int32)

    Declaration
    public static bool op_LessThan(int a, int b)
    Parameters
    Type Name Description
    Int32 a
    Int32 b
    Returns
    Type Description
    Boolean

    op_LessThanOrEqual(Int32, Int32)

    Declaration
    public static bool op_LessThanOrEqual(int a, int b)
    Parameters
    Type Name Description
    Int32 a
    Int32 b
    Returns
    Type Description
    Boolean

    op_Subtraction(Int32, Int32)

    Declaration
    public static int op_Subtraction(int a, int b)
    Parameters
    Type Name Description
    Int32 a
    Int32 b
    Returns
    Type Description
    Int32

    op_UnaryNegation(Int32)

    Declaration
    public static int op_UnaryNegation(int a)
    Parameters
    Type Name Description
    Int32 a
    Returns
    Type Description
    Int32

    PrintTypes(Type[])

    Declaration
    public static string PrintTypes(Type[] types)
    Parameters
    Type Name Description
    Type[] types
    Returns
    Type Description
    String

    SetValue(Object, Object[])

    Set an element in an array or collection.

    Declaration
    public static void SetValue(object target, params object[] args)
    Parameters
    Type Name Description
    Object target

    An array or collection.

    Object[] args

    Indices followed by the value to set. Length > 0.

    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.