Show / Hide Table of Contents

Class Type<T>

Provides typed access to class or value type metadata.

Inheritance
Object
Type<T>
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 Source

Equals

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 method. For value type, it calls equality operator or if it is implemented by the value type; else, it calls .

| Improve this Doc View Source

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 virtual method. For value type, it calls if it is overridden by the value type; otherwise, it calls .

Properties

| Improve this Doc View Source

Default

Returns default value for this type.

Declaration
public static T Default { get; }
Property Value
Type Description
T
| Improve this Doc View Source

RuntimeType

Gets reflected type.

Declaration
public static Type RuntimeType { get; }
Property Value
Type Description
DotNext.Reflection.Type

Methods

| Improve this Doc View Source

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

| Improve this Doc View Source

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 T; or null, if it doesn't exist.

Type Parameters
Name Description
A

A structure describing constructor signature.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 U can be assigned to type T.

Type Parameters
Name Description
U

The type to compare with the current type.

| Improve this Doc View Source

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 T can be assigned to type U.

Type Parameters
Name Description
U

The type to compare with the current type.

| Improve this Doc View Source

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

Type Parameters
Name Description
A

A structure describing constructor signature.

Exceptions
Type Condition
MissingConstructorException

Constructor doesn't exist.

| Improve this Doc View Source

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

Type Parameters
Name Description
A

A structure describing constructor signature.

Exceptions
Type Condition
MissingConstructorException

Constructor doesn't exist.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX