Class Type<T>
Provides typed access to class or value type metadata.
Inherited Members
Namespace: DotNext.Reflection
Assembly: DotNext.Reflection.dll
Syntax
public static class Type<T>
Type Parameters
Name | Description |
---|---|
T | Reflected type. |
Fields
| Improve this Doc View SourceEquals
Provides smart equality check.
Declaration
public static readonly Operator<T, T, bool> Equals
Field Value
Type | Description |
---|---|
Operator<T, T, Boolean> |
Remarks
If type T
has equality operator then use it.
Otherwise, for reference types, this delegate always calls Equals(Object, Object) method.
For value type, it calls equality operator or Equals(T) if it is implemented by the value type; else,
it calls
GetHashCode
Provides smart hash code computation.
Declaration
public static readonly Operator<T, int> GetHashCode
Field Value
Type | Description |
---|---|
Operator<T, Int32> |
Remarks
For reference types, this delegate always calls GetHashCode() virtual method.
For value type, it calls GetHashCode() if it is overridden by the value type; otherwise,
it calls
Properties
| Improve this Doc View SourceDefault
Returns default value for this type.
Declaration
public static T Default { get; }
Property Value
Type | Description |
---|---|
T |
RuntimeType
Gets reflected type.
Declaration
public static Type RuntimeType { get; }
Property Value
Type | Description |
---|---|
Type |
Methods
| Improve this Doc View SourceConvert<TSource>(TSource)
Converts object into type T
.
Declaration
public static T Convert<TSource>(TSource value)
Parameters
Type | Name | Description |
---|---|---|
TSource | value | The value to convert. |
Returns
Type | Description |
---|---|
T | Converted value. |
Type Parameters
Name | Description |
---|---|
TSource | Type of value to convert. |
Remarks
Semantics of this method includes typecast as well as conversion between numeric types and implicit/explicit cast operators.
Exceptions
Type | Condition |
---|---|
InvalidCastException | Cannot convert values. |
GetConstructor<TArgs>(Boolean)
Reflects constructor as function.
Declaration
public static Constructor<Function<TArgs, T>> GetConstructor<TArgs>(bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
Boolean | nonPublic | true to reflect non-public constructor. |
Returns
Type | Description |
---|---|
Constructor<Function<TArgs, T>> | Constructor for type |
Type Parameters
Name | Description |
---|---|
TArgs | A structure describing constructor signature. |
GetMethod<TArgs>(String, Boolean)
Reflects instance method declared in type T
without return value
and has arguments described by type TArgs
.
Declaration
public static Method<Procedure<T, TArgs>> GetMethod<TArgs>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Procedure<T, TArgs>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<T, TArgs> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
GetMethod<TArgs, TResult>(String, Boolean)
Reflects instance method declared in type T
which
returns value of type TResult
and has arguments described
by type TArgs
.
Declaration
public static Method<Function<T, TArgs, TResult>> GetMethod<TArgs, TResult>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Function<T, TArgs, TResult>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
TResult | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<T, TArgs, TResult> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
GetStaticMethod<TArgs>(String, Boolean)
Reflects static method declared in type T
without return value
and has arguments described by type TArgs
.
Declaration
public static Method<Procedure<TArgs>> GetStaticMethod<TArgs>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Procedure<TArgs>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<TArgs> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
GetStaticMethod<TArgs, TResult>(String, Boolean)
Reflects static method declared in type T
which
returns value of type TResult
and has arguments described
by type TArgs
.
Declaration
public static Method<Function<TArgs, TResult>> GetStaticMethod<TArgs, TResult>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Function<TArgs, TResult>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
TResult | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<TArgs, TResult> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
Initialize()
Calls static constructor of type T
.
Declaration
public static void Initialize()
Remarks
This method doesn't call static constructor if type is already initialized.
IsAssignableFrom<TOther>()
Determines whether an instance of a specified type can be assigned to an instance of the current type.
Declaration
public static bool IsAssignableFrom<TOther>()
Returns
Type | Description |
---|---|
Boolean | true, if instance of type |
Type Parameters
Name | Description |
---|---|
TOther | The type to compare with the current type. |
IsAssignableTo<TOther>()
Determines whether an instance of the current type can be assigned to an instance of the specified type.
Declaration
public static bool IsAssignableTo<TOther>()
Returns
Type | Description |
---|---|
Boolean | true, if instance of type |
Type Parameters
Name | Description |
---|---|
TOther | The type to compare with the current type. |
NewInstance<TArgs>(TArgs, Boolean)
Creates a new instance of type T
.
Declaration
public static T NewInstance<TArgs>(in TArgs args, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
TArgs | args | The structure containing arguments to be passed into constructor. |
Boolean | nonPublic | True to reflect non-public constructor. |
Returns
Type | Description |
---|---|
T | A new instance of type |
Type Parameters
Name | Description |
---|---|
TArgs | A structure describing constructor signature. |
Exceptions
Type | Condition |
---|---|
MissingConstructorException | Constructor doesn't exist. |
RequireConstructor<TArgs>(Boolean)
Reflects constructor as function.
Declaration
public static Constructor<Function<TArgs, T>> RequireConstructor<TArgs>(bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
Boolean | nonPublic | true to reflect non-public constructor. |
Returns
Type | Description |
---|---|
Constructor<Function<TArgs, T>> | Constructor for type |
Type Parameters
Name | Description |
---|---|
TArgs | A structure describing constructor signature. |
Exceptions
Type | Condition |
---|---|
MissingConstructorException | Constructor doesn't exist. |
RequireMethod<TArgs>(String, Boolean)
Reflects instance method declared in type T
without return value
and has arguments described by type TArgs
.
Declaration
public static Method<Procedure<T, TArgs>> RequireMethod<TArgs>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Procedure<T, TArgs>> | The reflected method; or null. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<T, TArgs> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
Exceptions
Type | Condition |
---|---|
MissingMethodException | The method doesn't exist. |
RequireMethod<TArgs, TResult>(String, Boolean)
Reflects instance method declared in type T
which
returns value of type TResult
and has arguments described
by type TArgs
.
Declaration
public static Method<Function<T, TArgs, TResult>> RequireMethod<TArgs, TResult>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Function<T, TArgs, TResult>> | The reflected method. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
TResult | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<T, TArgs, TResult> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
Exceptions
Type | Condition |
---|---|
MissingMethodException | The method doesn't exist. |
RequireStaticMethod<TArgs>(String, Boolean)
Reflects static method declared in type T
without return value
and has arguments described by type TArgs
.
Declaration
public static Method<Procedure<TArgs>> RequireStaticMethod<TArgs>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Procedure<TArgs>> | The reflected method; or null. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<TArgs> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
Exceptions
Type | Condition |
---|---|
MissingMethodException | The method doesn't exist. |
RequireStaticMethod<TArgs, TResult>(String, Boolean)
Reflects static method declared in type T
which
returns value of type TResult
and has arguments described
by type TArgs
.
Declaration
public static Method<Function<TArgs, TResult>> RequireStaticMethod<TArgs, TResult>(string methodName, bool nonPublic = false)
where TArgs : struct
Parameters
Type | Name | Description |
---|---|---|
String | methodName | The name of the method. |
Boolean | nonPublic | true to reflect non-public method. |
Returns
Type | Description |
---|---|
Method<Function<TArgs, TResult>> | The reflected method. |
Type Parameters
Name | Description |
---|---|
TArgs | The value type describing arguments of the method. |
TResult | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<TArgs, TResult> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
Exceptions
Type | Condition |
---|---|
MissingMethodException | The method doesn't exist. |
TryConvert<TSource>(TSource)
Applies type cast to the given object respecting overloaded cast operator.
Declaration
public static Optional<T> TryConvert<TSource>(TSource value)
Parameters
Type | Name | Description |
---|---|---|
TSource | value | The value to be converted. |
Returns
Type | Description |
---|---|
Optional<T> | Optional conversion result if it is supported for the given type. |
Type Parameters
Name | Description |
---|---|
TSource | The type of object to be converted. |
TryConvert<TSource>(TSource, out T)
Applies type cast to the given object respecting overloaded cast operator.
Declaration
public static bool TryConvert<TSource>(TSource value, out T result)
Parameters
Type | Name | Description |
---|---|---|
TSource | value | The value to be converted. |
T | result | The conversion result. |
Returns
Type | Description |
---|---|
Boolean | true, if conversion is supported by the given type; otherwise, false. |
Type Parameters
Name | Description |
---|---|
TSource | The type of object to be converted. |