Class Type<T>
Provides typed access to class or value type metadata.
Namespace: DotNext.Reflection
Assembly: DotNext.Reflection.dll
Syntax
public static class Type<T> : object
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
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
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 |
---|---|
DotNext.Reflection.Type |
Methods
| Improve this Doc View SourceConvert<U>(U)
Converts object into type T
.
Declaration
public static T Convert<U>(U value)
Parameters
Type | Name | Description |
---|---|---|
U | value | The value to convert. |
Returns
Type | Description |
---|---|
T | Converted value. |
Type Parameters
Name | Description |
---|---|
U | Type of value to convert. |
Remarks
Semantics of this method includes typecast as well as conversion between numeric types and implicit/explicit cast operators.
GetConstructor<A>(Boolean)
Reflects constructor as function.
Declaration
public static Constructor<Function<A, T>> GetConstructor<A>(bool nonPublic = false)
where A : struct
Parameters
Type | Name | Description |
---|---|---|
Boolean | nonPublic | true to reflect non-public constructor. |
Returns
Type | Description |
---|---|
Constructor<Function<A, T>> | Constructor for type |
Type Parameters
Name | Description |
---|---|
A | A structure describing constructor signature. |
GetMethod<A>(String, Boolean)
Reflects instance method declared in type T
without return value
and has arguments described by type A
.
Declaration
public static Method<Procedure<T, A>> GetMethod<A>(string methodName, bool nonPublic = false)
where A : 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, A>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<T, A> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
GetMethod<A, R>(String, Boolean)
Reflects instance method declared in type T
which
returns value of type R
and has arguments described
by type A
.
Declaration
public static Method<Function<T, A, R>> GetMethod<A, R>(string methodName, bool nonPublic = false)
where A : 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, A, R>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
R | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<T, A, R> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
GetStaticMethod<A>(String, Boolean)
Reflects static method declared in type T
without return value
and has arguments described by type A
.
Declaration
public static Method<Procedure<A>> GetStaticMethod<A>(string methodName, bool nonPublic = false)
where A : 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<A>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<A> which allocates arguments on the stack instead of registry-based allocated or any other optimizations performed by .NET Runtime.
GetStaticMethod<A, R>(String, Boolean)
Reflects static method declared in type T
which
returns value of type R
and has arguments described
by type A
.
Declaration
public static Method<Function<A, R>> GetStaticMethod<A, R>(string methodName, bool nonPublic = false)
where A : 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<A, R>> | The reflected method; or null if method doesn't exist. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
R | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<A, R> 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<U>()
Determines whether an instance of a specified type can be assigned to an instance of the current type.
Declaration
public static bool IsAssignableFrom<U>()
Returns
Type | Description |
---|---|
Boolean | true, if instance of type |
Type Parameters
Name | Description |
---|---|
U | The type to compare with the current type. |
IsAssignableTo<U>()
Determines whether an instance of the current type can be assigned to an instance of the specified type.
Declaration
public static bool IsAssignableTo<U>()
Returns
Type | Description |
---|---|
Boolean | true, if instance of type |
Type Parameters
Name | Description |
---|---|
U | The type to compare with the current type. |
NewInstance<A>(A, Boolean)
Creates a new instance of type T
.
Declaration
public static T NewInstance<A>(in A args, bool nonPublic = false)
where A : struct
Parameters
Type | Name | Description |
---|---|---|
A | 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 |
---|---|
A | A structure describing constructor signature. |
Exceptions
Type | Condition |
---|---|
MissingConstructorException | Constructor doesn't exist. |
RequireConstructor<A>(Boolean)
Reflects constructor as function.
Declaration
public static Constructor<Function<A, T>> RequireConstructor<A>(bool nonPublic = false)
where A : struct
Parameters
Type | Name | Description |
---|---|---|
Boolean | nonPublic | true to reflect non-public constructor. |
Returns
Type | Description |
---|---|
Constructor<Function<A, T>> | Constructor for type |
Type Parameters
Name | Description |
---|---|
A | A structure describing constructor signature. |
Exceptions
Type | Condition |
---|---|
MissingConstructorException | Constructor doesn't exist. |
RequireMethod<A>(String, Boolean)
Reflects instance method declared in type T
without return value
and has arguments described by type A
.
Declaration
public static Method<Procedure<T, A>> RequireMethod<A>(string methodName, bool nonPublic = false)
where A : 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, A>> | The reflected method; or null. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<T, A> 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<A, R>(String, Boolean)
Reflects instance method declared in type T
which
returns value of type R
and has arguments described
by type A
.
Declaration
public static Method<Function<T, A, R>> RequireMethod<A, R>(string methodName, bool nonPublic = false)
where A : 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, A, R>> | The reflected method. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
R | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<T, A, R> 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<A>(String, Boolean)
Reflects static method declared in type T
without return value
and has arguments described by type A
.
Declaration
public static Method<Procedure<A>> RequireStaticMethod<A>(string methodName, bool nonPublic = false)
where A : 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<A>> | The reflected method; or null. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
Remarks
The reflected method is represented by universal delegate type Procedure<A> 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<A, R>(String, Boolean)
Reflects static method declared in type T
which
returns value of type R
and has arguments described
by type A
.
Declaration
public static Method<Function<A, R>> RequireStaticMethod<A, R>(string methodName, bool nonPublic = false)
where A : 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<A, R>> | The reflected method. |
Type Parameters
Name | Description |
---|---|
A | The value type describing arguments of the method. |
R | The method return type. |
Remarks
The reflected method is represented by universal delegate type Function<A, R> 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<U>(U)
Applies type cast to the given object respecting overloaded cast operator.
Declaration
public static Optional<T> TryConvert<U>(U value)
Parameters
Type | Name | Description |
---|---|---|
U | 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 |
---|---|
U | The type of object to be converted. |
TryConvert<U>(U, out T)
Applies type cast to the given object respecting overloaded cast operator.
Declaration
public static bool TryConvert<U>(U value, out T result)
Parameters
Type | Name | Description |
---|---|---|
U | 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 |
---|---|
U | The type of object to be converted. |