Show / Hide Table of Contents

Class Type<T>

Provides typed access to class or value type metadata.

Inheritance
Object
Type<T>
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
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 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 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 .

| 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 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 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
Type

Methods

| Improve this Doc View Source

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

| Improve this Doc View Source

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

Type Parameters
Name Description
TArgs

A structure describing constructor signature.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

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

Type Parameters
Name Description
TOther

The type to compare with the current type.

| Improve this Doc View Source

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

Type Parameters
Name Description
TOther

The type to compare with the current type.

| Improve this Doc View Source

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

Type Parameters
Name Description
TArgs

A structure describing constructor signature.

Exceptions
Type Condition
MissingConstructorException

Constructor doesn't exist.

| Improve this Doc View Source

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

Type Parameters
Name Description
TArgs

A structure describing constructor signature.

Exceptions
Type Condition
MissingConstructorException

Constructor doesn't exist.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

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