Version 2.1.0.0

MemberFinder class

Namespace: Sirenix.Utilities
Assembly: Sirenix.Utilities
public class MemberFinder

The MemberFinder is a utility class often used by Odin drawers to find fields, methods, and properties while providing good user-friendly error messages based on the search criteria.

The MemberFinder is initialized by ether using the extensions method type.FindMember() or MemberFinder.Start(type), and must be ended again using ether TryGetMember() or GetMember().

Inheritance
  • System.Object
  • MemberFinder
Example
// Finds any member (FieldInfo, PropertyInfo or MethodInfo) "memberName" with a return type of string.
string errorMessage;
MemberInfo myMember = typeof(MyType)
                        .FindMember()
                        .IsNamed("memberName")
                        .HasReturnType(typeof(string))
                        .HasNoParameters()
                        .GetMember(out errorMessage);
If no matching member was found, myMember will be null and errorMessage will contain a proper formatted error message based on the search filters provided.

Constructors

MemberFinder()
Initializes a new instance of the MemberFinder class.
public MemberFinder()
MemberFinder(Type)
Initializes a new instance of the MemberFinder class.
public MemberFinder(Type type)
Parameters
System.Type type

Methods

GetMember(out String)

Gets the member based on the search filters provided, and provides a proper error message if no members was found.

public MemberInfo GetMember(out string errorMessage)
Parameters
System.String errorMessage

Returns
System.Reflection.MemberInfo

GetMember<T>()

Gets the member based on the search filters provided

Returns null if no member was found.

public T GetMember<T>()
    where T : MemberInfo
Returns
T

Type Parameters
T

GetMember<T>(out String)

Gets the member based on the search filters provided, and provides a proper error message if no members was found.

public T GetMember<T>(out string errorMessage)
    where T : MemberInfo
Parameters
System.String errorMessage

Returns
T

Type Parameters
T

HasNoParameters()
Can be true for both fields, properties and methods.
public MemberFinder HasNoParameters()
Returns
MemberFinder

HasParameters(Type)

Only include methods with the following parameter.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters(Type param1)
Parameters
System.Type param1

Returns
MemberFinder

HasParameters(Type, Type)

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters(Type param1, Type param2)
Parameters
System.Type param1

System.Type param2

Returns
MemberFinder

HasParameters(Type, Type, Type)

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters(Type param1, Type param2, Type param3)
Parameters
System.Type param1

System.Type param2

System.Type param3

Returns
MemberFinder

HasParameters(Type, Type, Type, Type)

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters(Type param1, Type param2, Type param3, Type param4)
Parameters
System.Type param1

System.Type param2

System.Type param3

System.Type param4

Returns
MemberFinder

HasParameters<T>()

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters<T>()
Returns
MemberFinder

Type Parameters
T

HasParameters<T1, T2>()

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters<T1, T2>()
Returns
MemberFinder

Type Parameters
T1

T2

HasParameters<T1, T2, T3>()

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters<T1, T2, T3>()
Returns
MemberFinder

Type Parameters
T1

T2

T3

HasParameters<T1, T2, T3, T4>()

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

public MemberFinder HasParameters<T1, T2, T3, T4>()
Returns
MemberFinder

Type Parameters
T1

T2

T3

T4

HasReturnType(Type, Boolean)
Determines whether [has return type] [the specified return type].
public MemberFinder HasReturnType(Type returnType, bool inherit = false)
Parameters
System.Type returnType

System.Boolean inherit

Returns
MemberFinder

HasReturnType<T>(Boolean)
Can be true for both fields, properties and methods.
public MemberFinder HasReturnType<T>(bool inherit = false)
Parameters
System.Boolean inherit

Returns
MemberFinder

Type Parameters
T

IsDeclaredOnly()
Exclude members found in base-types.
public MemberFinder IsDeclaredOnly()
Returns
MemberFinder

IsField()

Excludes properties and methods if nether IsProperty() or IsMethod() is called. Otherwise includes fields.

By default, all member types are included.

public MemberFinder IsField()
Returns
MemberFinder

IsFieldOrProperty()
Calls IsField() and IsProperty().
public MemberFinder IsFieldOrProperty()
Returns
MemberFinder

IsInstance()
Only include non-static members. By default, both static and non-static members are included.
public MemberFinder IsInstance()
Returns
MemberFinder

IsMethod()

Excludes fields and properties if nether IsField() or IsProperty() is called. Otherwise includes methods.

By default, all member types are included.

public MemberFinder IsMethod()
Returns
MemberFinder

IsNamed(Object)
public bool IsNamed(object customDeleteFunction)
Parameters
System.Object customDeleteFunction

Returns
System.Boolean

IsNamed(String)
Specify the name of the member.
public MemberFinder IsNamed(string name)
Parameters
System.String name

Returns
MemberFinder

IsNonPublic()

Excludes public members if IsPublic() has not yet been called. Otherwise includes non-public members.

By default, both public and non-public members are included.

public MemberFinder IsNonPublic()
Returns
MemberFinder

IsProperty()

Excludes fields and methods if nether IsField() or IsMethod() is called. Otherwise includes properties.

By default, all member types are included.

public MemberFinder IsProperty()
Returns
MemberFinder

IsPublic()

Excludes non-public members if IsNonPublic() has not yet been called. Otherwise includes public members.

By default, both public and non-public members are included.

public MemberFinder IsPublic()
Returns
MemberFinder

IsStatic()
Only include static members. By default, both static and non-static members are included.
public MemberFinder IsStatic()
Returns
MemberFinder

ReturnsVoid()
Excludes fields and properties, and only includes methods with a return type of void.
public MemberFinder ReturnsVoid()
Returns
MemberFinder

Start(Type)

Find members of the given type, while providing good error messages based on the following search filters provided.

public static MemberFinder Start(Type type)
Parameters
System.Type type

Returns
MemberFinder

Start<T>()

Find members of the given type, while providing good error messages based on the following search filters provided.

public static MemberFinder Start<T>()
Returns
MemberFinder

Type Parameters
T

TryGetMember(out MemberInfo, out String)

Try gets the member based on the search filters provided, and provides a proper error message if no members was found.

public bool TryGetMember(out MemberInfo memberInfo, out string errorMessage)
Parameters
System.Reflection.MemberInfo memberInfo

System.String errorMessage

Returns
System.Boolean

TryGetMember<T>(out T, out String)

Try gets the member based on the search filters provided, and provides a proper error message if no members was found.

public bool TryGetMember<T>(out T memberInfo, out string errorMessage)
    where T : MemberInfo
Parameters
T memberInfo

System.String errorMessage

Returns
System.Boolean

Type Parameters
T

TryGetMembers(out MemberInfo[], out String)

Try gets all members based on the search filters provided, and provides a proper error message if no members was found.

public bool TryGetMembers(out MemberInfo[] memberInfos, out string errorMessage)
Parameters
System.Reflection.MemberInfo[] memberInfos

System.String errorMessage

Returns
System.Boolean

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.