Search Results for

    Show / Hide Table of Contents

    Class ReflectionUtil

    A utility class providing reflection helper methods.

    Inheritance
    System.Object
    ReflectionUtil
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: IPA.Utilities
    Assembly: IPA.Loader.dll
    Syntax
    public static class ReflectionUtil

    Methods

    | Improve this Doc View Source

    CopyComponent(Component, Type, GameObject, Type)

    Copies a component original to a component of overridingType on the destination UnityEngine.GameObject.

    Declaration
    public static Component CopyComponent(this Component original, Type overridingType, GameObject destination, Type originalTypeOverride = null)
    Parameters
    Type Name Description
    UnityEngine.Component original

    the original component

    System.Type overridingType

    the new component's type

    UnityEngine.GameObject destination

    the destination GameObject

    System.Type originalTypeOverride

    overrides the source component type (for example, to a superclass)

    Returns
    Type Description
    UnityEngine.Component

    the copied component

    | Improve this Doc View Source

    CopyComponent<T>(Component, GameObject, Type)

    A generic version of CopyComponent(Component, Type, GameObject, Type).

    Declaration
    public static T CopyComponent<T>(this Component original, GameObject destination, Type originalTypeOverride = null)
        where T : Component
    Parameters
    Type Name Description
    UnityEngine.Component original

    the original component

    UnityEngine.GameObject destination

    the destination game object

    System.Type originalTypeOverride

    overrides the source component type (for example, to a superclass)

    Returns
    Type Description
    T

    the copied component

    Type Parameters
    Name Description
    T

    the overriding type

    See Also
    CopyComponent(Component, Type, GameObject, Type)
    | Improve this Doc View Source

    GetField<U, T>(T, String)

    Gets the value of a field.

    Declaration
    public static U GetField<U, T>(this T obj, string fieldName)
    Parameters
    Type Name Description
    T obj

    the object instance to pull from

    System.String fieldName

    the name of the field to read

    Returns
    Type Description
    U

    the value of the field

    Type Parameters
    Name Description
    U

    the type of the field (result casted)

    T

    the type to get the field from

    Exceptions
    Type Condition
    System.MissingFieldException

    if fieldName does not exist on T

    See Also
    Get(ref T, String)
    | Improve this Doc View Source

    GetProperty<U, T>(T, String)

    Gets a property on the target object, as gotten from T.

    Declaration
    public static U GetProperty<U, T>(this T obj, string propertyName)
    Parameters
    Type Name Description
    T obj

    the object instance

    System.String propertyName

    the property to get

    Returns
    Type Description
    U

    the value of the property

    Type Parameters
    Name Description
    U

    the type of the property to get

    T

    the type to get the property from

    Exceptions
    Type Condition
    System.MissingMemberException

    if propertyName does not exist on T

    See Also
    Get(ref T, String)
    | Improve this Doc View Source

    InvokeMethod<U, T>(T, String, Object[])

    Invokes a method from T on an object.

    Declaration
    public static U InvokeMethod<U, T>(this T obj, string methodName, params object[] args)
    Parameters
    Type Name Description
    T obj

    the object instance

    System.String methodName

    the method's name

    System.Object[] args

    the method arguments

    Returns
    Type Description
    U

    the return value

    Type Parameters
    Name Description
    U

    the type that the method returns

    T

    the type to search for the method on

    Exceptions
    Type Condition
    System.MissingMethodException

    if methodName does not exist on T

    | Improve this Doc View Source

    SetField<T, U>(T, String, U)

    Sets a field on the target object, as gotten from T.

    Declaration
    public static void SetField<T, U>(this T obj, string fieldName, U value)
    Parameters
    Type Name Description
    T obj

    the object instance

    System.String fieldName

    the field to set

    U value

    the value to set it to

    Type Parameters
    Name Description
    T

    the type to get the field from

    U

    the type of the field to set

    Exceptions
    Type Condition
    System.MissingFieldException

    if fieldName does not exist on T

    See Also
    Set(ref T, String, U)
    | Improve this Doc View Source

    SetProperty<T, U>(T, String, U)

    Sets a property on the target object, as gotten from T.

    Declaration
    public static void SetProperty<T, U>(this T obj, string propertyName, U value)
    Parameters
    Type Name Description
    T obj

    the object instance

    System.String propertyName

    the property to set

    U value

    the value to set it to

    Type Parameters
    Name Description
    T

    the type to get the property from

    U

    the type of the property to set

    Exceptions
    Type Condition
    System.MissingMemberException

    if propertyName does not exist on T

    See Also
    Set(ref T, String, U)
    | Improve this Doc View Source

    ToCompilerGeneratedBackingField(String)

    Converts the property name to the one of the compiler-generated backing field. This can be used for the field-based reflection when you want to set the value of a get-only property

    Declaration
    public static string ToCompilerGeneratedBackingField(string propertyName)
    Parameters
    Type Name Description
    System.String propertyName

    Name of the property

    Returns
    Type Description
    System.String

    Name of the backing field

    Remarks

    Only works for properties with compiler-generated backing fields. This is only a simple method and doesn't have any guarantees to work 100% of the time across different compilers/runtimes. See this link for more info.

    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX