Class ReflectionHelpers
Provides various utilities for reflection.
Inheritance
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public static class ReflectionHelpers : Object
Methods
InfoOf(Expression)
Gets the reflection member information from the top-level node in the body of the given lambda expression.
Declaration
public static MemberInfo InfoOf(Expression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | expression | Lambda expression to extract reflection information from |
Returns
Type | Description |
---|---|
System.Reflection.MemberInfo | Member information of the top-level node in the body of the lambda expression. An exception occurs if this node does not contain member information. |
InfoOf(Expression<Action>)
Gets the reflection member information from the top-level node in the body of the given lambda expression.
Declaration
public static MemberInfo InfoOf(Expression<Action> expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Action> | expression | Lambda expression to extract reflection information from |
Returns
Type | Description |
---|---|
System.Reflection.MemberInfo | Member information of the top-level node in the body of the lambda expression. An exception occurs if this node does not contain member information. |
Examples
To obtain the MethodInfo for the "void Console::WriteLine()" overload, you can write:
(MethodInfo)ReflectionHelpers.InfoOf(() => Console.WriteLine())
InfoOf<T>(Expression<Action<T>>)
Gets the reflection member information from the top-level node in the body of the given lambda expression.
Declaration
public static MemberInfo InfoOf<T>(Expression<Action<T>> expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Action<T>> | expression | Lambda expression to extract reflection information from |
Returns
Type | Description |
---|---|
System.Reflection.MemberInfo | Member information of the top-level node in the body of the lambda expression. An exception occurs if this node does not contain member information. |
Type Parameters
Name | Description |
---|---|
T | Input type of the lambda. |
Examples
To obtain the MethodInfo for the "void Console::WriteLine(string)" overload, you can write:
(MethodInfo)ReflectionHelpers.InfoOf((string s) => Console.WriteLine(s))
InfoOf<TResult>(Expression<Func<TResult>>)
Gets the reflection member information from the top-level node in the body of the given lambda expression.
Declaration
public static MemberInfo InfoOf<TResult>(Expression<Func<TResult>> expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<TResult>> | expression | Lambda expression to extract reflection information from |
Returns
Type | Description |
---|---|
System.Reflection.MemberInfo | Member information of the top-level node in the body of the lambda expression. An exception occurs if this node does not contain member information. |
Type Parameters
Name | Description |
---|---|
TResult | Return type of the lambda. |
Examples
To obtain the PropertyInfo of "DateTime DateTime::Now { get; }", you can write:
(PropertyInfo)ReflectionHelpers.InfoOf(() => DateTime.Now)
InfoOf<T, TResult>(Expression<Func<T, TResult>>)
Gets the reflection member information from the top-level node in the body of the given lambda expression.
Declaration
public static MemberInfo InfoOf<T, TResult>(Expression<Func<T, TResult>> expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<T, TResult>> | expression | Lambda expression to extract reflection information from |
Returns
Type | Description |
---|---|
System.Reflection.MemberInfo | Member information of the top-level node in the body of the lambda expression. An exception occurs if this node does not contain member information. |
Type Parameters
Name | Description |
---|---|
T | Input type of the lambda. |
TResult | Return type of the lambda. |
Examples
To obtain the MethodInfo for the "int Math::Abs(int)" overload, you can write:
(MethodInfo)ReflectionHelpers.InfoOf((int x) => Math.Abs(x))