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().

namespace Sirenix.Utilities
{
public class MemberFinder
}

Requirements

Namespace: Sirenix.Utilities
Assembly: Sirenix.OdinInspector
Version: 2.0.0.0

Static Methods

Return Type Definition Description
MemberFinder Start(Type)

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

MemberFinder Start<T>()

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

Constructors

Definition Description
MemberFinder() Initializes a new instance of the MemberFinder class.
MemberFinder(Type) Initializes a new instance of the MemberFinder class.

Methods

Return Type Definition Description
MemberInfo GetMember(ref string)

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

T GetMember<T>()

Gets the member based on the search filters provided

Returns null if no member was found.

T GetMember<T>(ref string)

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

MemberFinder HasNoParameters() Can be true for both fields, properties and methods.
MemberFinder HasParameters(Type)

Only include methods with the following parameter.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

MemberFinder HasParameters(Type, Type)

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

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.

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.

MemberFinder HasParameters<T>()

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

MemberFinder 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.

MemberFinder HasParameters<T1, T2, T3>()

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

MemberFinder HasParameters<T1, T2>()

Only include methods with the following parameters.

Calling this will also exclude fields and properties.

Parameter type inheritance is supported.

MemberFinder HasReturnType(Type, bool) Determines whether [has return type] [the specified return type].
MemberFinder HasReturnType<T>(bool) Can be true for both fields, properties and methods.
MemberFinder IsDeclaredOnly() Exclude members found in base-types.
MemberFinder IsField()

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

By default, all member types are included.

MemberFinder IsFieldOrProperty() Calls IsField() and IsProperty().
MemberFinder IsInstance() Only include non-static members. By default, both static and non-static members are included.
MemberFinder IsMethod()

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

By default, all member types are included.

MemberFinder IsNamed(string) Specify the name of the member.
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.

MemberFinder IsProperty()

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

By default, all member types are included.

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.

MemberFinder IsStatic() Only include static members. By default, both static and non-static members are included.
MemberFinder ReturnsVoid() Excludes fields and properties, and only includes methods with a return type of void.
bool TryGetMember(ref MemberInfo, ref string)

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

bool TryGetMember<T>(ref T, ref string)

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

bool TryGetMembers(ref MemberInfo[], ref string)

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

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.