Class Reflection
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
Helper class for handling Reflection amd Expression tree related items.
public static class Reflection
- Inheritance
-
Reflection
Methods
ExpressionToPropertyNames(Expression?)
Will convert a Expression which points towards a property to a string containing the property names. The sub-properties will be separated by the '.' character. Index based values will include [] after the name.
public static string ExpressionToPropertyNames(Expression? expression)
Parameters
expression
ExpressionThe expression to generate the property names from.
Returns
- string
A string form for the property the expression is pointing to.
GetEventArgsTypeForEvent(Type, string?)
Gets the appropriate EventArgs derived object for the specified event name for a Type.
public static Type GetEventArgsTypeForEvent(Type type, string? eventName)
Parameters
Returns
- Type
The Type of the EventArgs to use.
Exceptions
- Exception
If there is no event matching the name on the target type.
GetValueFetcherForProperty(MemberInfo?)
Converts a MemberInfo into a Func which will fetch the value for the Member. Handles either fields or properties.
public static Func<object?, object?[]?, object?>? GetValueFetcherForProperty(MemberInfo? member)
Parameters
member
MemberInfoThe member info to convert.
Returns
GetValueFetcherOrThrow(MemberInfo?)
Converts a MemberInfo into a Func which will fetch the value for the Member. Handles either fields or properties. If there is no field or property with the matching MemberInfo it'll throw an ArgumentException.
public static Func<object?, object?[]?, object?> GetValueFetcherOrThrow(MemberInfo? member)
Parameters
member
MemberInfoThe member info to convert.
Returns
GetValueSetterForProperty(MemberInfo?)
Converts a MemberInfo into a Func which will set the value for the Member. Handles either fields or properties. If there is no field or property with the matching MemberInfo it'll throw an ArgumentException.
public static Action<object?, object?, object?[]?> GetValueSetterForProperty(MemberInfo? member)
Parameters
member
MemberInfoThe member info to convert.
Returns
GetValueSetterOrThrow(MemberInfo?)
Converts a MemberInfo into a Func which will set the value for the Member. Handles either fields or properties. If there is no field or property with the matching MemberInfo it'll throw an ArgumentException.
public static Action<object?, object?, object?[]?>? GetValueSetterOrThrow(MemberInfo? member)
Parameters
member
MemberInfoThe member info to convert.
Returns
IsStatic(PropertyInfo)
Determines if the specified property is static or not.
public static bool IsStatic(this PropertyInfo item)
Parameters
item
PropertyInfoThe property information to check.
Returns
- bool
If the property is static or not.
ReallyFindType(string?, bool)
Gets a Type from the specified type name. Uses a cache to avoid having to use Reflection every time.
public static Type? ReallyFindType(string? type, bool throwOnFailure)
Parameters
type
stringThe name of the type.
throwOnFailure
boolIf we should throw an exception if the type can't be found.
Returns
- Type
The type that was found or null.
Exceptions
- TypeLoadException
If we were unable to find the type.
Rewrite(Expression?)
Uses the expression re-writer to simplify the Expression down to it's simplest Expression.
public static Expression Rewrite(Expression? expression)
Parameters
expression
ExpressionThe expression to rewrite.
Returns
- Expression
The rewritten expression.
ThrowIfMethodsNotOverloaded(string, object, params string[])
Checks to make sure that the specified method names on the target object are overriden.
public static void ThrowIfMethodsNotOverloaded(string callingTypeName, object targetObject, params string[] methodsToCheck)
Parameters
callingTypeName
stringThe name of the calling type.
targetObject
objectThe object to check.
methodsToCheck
string[]The name of the methods to check.
Exceptions
- Exception
Thrown if the methods aren't overriden on the target object.
TryGetAllValuesForPropertyChain(out IObservedChange<object, object?>[], object?, IEnumerable<Expression>)
Based on a list of Expressions get a IObservedChanged for the value of the last property in the chain if possible. The Expressions are property chains. Eg Property1.Property2.Property3 The method will make sure that each Expression can get a value along the way and get each property until each expression is evaluated.
public static bool TryGetAllValuesForPropertyChain(out IObservedChange<object, object?>[] changeValues, object? current, IEnumerable<Expression> expressionChain)
Parameters
changeValues
IObservedChange<object, object>[]A IObservedChanged for the value.
current
objectThe object that starts the property chain.
expressionChain
IEnumerable<Expression>A list of expressions which will point towards a property or field.
Returns
- bool
If the value was successfully retrieved or not.
TryGetValueForPropertyChain<TValue>(out TValue, object?, IEnumerable<Expression>)
Based on a list of Expressions get the value of the last property in the chain if possible. The Expressions are typically property chains. Eg Property1.Property2.Property3 The method will make sure that each Expression can get a value along the way and get each property until each expression is evaluated.
public static bool TryGetValueForPropertyChain<TValue>(out TValue changeValue, object? current, IEnumerable<Expression> expressionChain)
Parameters
changeValue
TValueA output value where to store the value if the value can be fetched.
current
objectThe object that starts the property chain.
expressionChain
IEnumerable<Expression>A list of expressions which will point towards a property or field.
Returns
- bool
If the value was successfully retrieved or not.
Type Parameters
TValue
The type of the end value we are trying to get.
TrySetValueToPropertyChain<TValue>(object?, IEnumerable<Expression>, TValue, bool)
Based on a list of Expressions set a value of the last property in the chain if possible. The Expressions are property chains. Eg Property1.Property2.Property3 The method will make sure that each Expression can use each value along the way and set the last value.
public static bool TrySetValueToPropertyChain<TValue>(object? target, IEnumerable<Expression> expressionChain, TValue value, bool shouldThrow = true)
Parameters
target
objectThe object that starts the property chain.
expressionChain
IEnumerable<Expression>A list of expressions which will point towards a property or field.
value
TValueThe value to set on the last property in the Expression chain.
shouldThrow
boolIf we should throw if we are unable to set the value.
Returns
- bool
If the value was successfully retrieved or not.
Type Parameters
TValue
The type of the end value we are trying to set.