Table of Contents

Class TypeExtensions

Namespace
Tripous
Assembly
Tripous.dll

Type related extension methods

public static class TypeExtensions
Inheritance
TypeExtensions
Inherited Members

Methods

Create(Type)

A kind of "virtual constructor" of any type of object. Example call for a constructor with no params/arguments Create(typeof(object));

public static object Create(this Type ClassType)

Parameters

ClassType Type

Returns

object

Create(Type, object[])

A kind of "virtual constructor" of any type of object. Example call for a constructor Create(typeof(object), new object[]{ });

public static object Create(this Type ClassType, object[] Args)

Parameters

ClassType Type
Args object[]

Returns

object

Create(Type, Type[], object[])

A kind of "virtual constructor" of any type of object. Example call for a constructor with no params/arguments Create(typeof(object), new Type[]{ }, new object[]{ });

public static object Create(this Type ClassType, Type[] Params, object[] Args)

Parameters

ClassType Type
Params Type[]
Args object[]

Returns

object

FindField(object, string)

Returns the value of a public or non-public field with FieldName which is declared in the type of the Instance or any of its ancestors. Returns null if the field is not found.

public static object FindField(object Instance, string FieldName)

Parameters

Instance object
FieldName string

Returns

object

FindField(Type, string)

Finds and returns a public or non-public FieldInfo with FieldName, if any in the Type or any base type, else null.

public static FieldInfo FindField(this Type Type, string FieldName)

Parameters

Type Type
FieldName string

Returns

FieldInfo

FindIntegerIndexer(Type)

Returns the one-dimensional integer indexer property of the ClassType, if it has one, otherwise null.

public static PropertyInfo FindIntegerIndexer(this Type ClassType)

Parameters

ClassType Type

Returns

PropertyInfo

FindPublicProperty(Type, string)

Finds the public instance property of ClassType by PropertyName

public static PropertyInfo FindPublicProperty(this Type ClassType, string PropertyName)

Parameters

ClassType Type
PropertyName string

Returns

PropertyInfo

GetArgTypes(object[])

Tries to infer Type-s of Args. If an Arg is null, it infers the typeof(object)

public static Type[] GetArgTypes(object[] Args)

Parameters

Args object[]

Returns

Type[]

GetDefaultFormat(Type)

Returns the default format string for the specified type.

public static string GetDefaultFormat(this Type T)

Parameters

T Type

Returns

string

GetFields(Type, Type)

Returns a list of public and non-public fields of the Type, including inherited fields. It includes fields up to LastType.

public static IList<FieldInfo> GetFields(this Type Type, Type LastType)

Parameters

Type Type
LastType Type

Returns

IList<FieldInfo>

GetPublicPropertyValue(object, string)

Returns the value of the public property PropertyName, if any, else null.

public static object GetPublicPropertyValue(object Instance, string PropertyName)

Parameters

Instance object
PropertyName string

Returns

object

GetPublicPropertyValue(Type, object, string)

Returns the value of the public prorperty PropertyName of Instance. Instance must be of type ClassType.

If Instance is null or Instance has not a PropertyName public property, null is returned.

public static object GetPublicPropertyValue(this Type ClassType, object Instance, string PropertyName)

Parameters

ClassType Type
Instance object
PropertyName string

Returns

object

HasDefaultConstructor(Type)

Returns true if a type defines a default public constructor

public static bool HasDefaultConstructor(this Type ClassType)

Parameters

ClassType Type

Returns

bool

HasPublicProperty(Type, string)

Returns true if the ClassType has a public instance property with PropertyName

public static bool HasPublicProperty(this Type ClassType, string PropertyName)

Parameters

ClassType Type
PropertyName string

Returns

bool

ImplementsInterface(Type, Type)

Returns true if ClassType implements InterfaceType.

public static bool ImplementsInterface(this Type ClassType, Type InterfaceType)

Parameters

ClassType Type
InterfaceType Type

Returns

bool

ImplementsInterfaces(Type, Type[])

Returns true if ClassType implements all InterfaceTypes.

public static bool ImplementsInterfaces(this Type ClassType, Type[] InterfaceTypes)

Parameters

ClassType Type
InterfaceTypes Type[]

Returns

bool

InheritsFrom(object, Type)

Returns true if Instance is a or inherits from Value.

public static bool InheritsFrom(this object Instance, Type Value)

Parameters

Instance object
Value Type

Returns

bool

InheritsFrom(Type, Type)

Returns true if ClassType is a or inherits from Value.

public static bool InheritsFrom(this Type ClassType, Type Value)

Parameters

ClassType Type
Value Type

Returns

bool

IsDateTime(Type)

Returns true if a specified type is a DateTime type

public static bool IsDateTime(this Type DataType)

Parameters

DataType Type

Returns

bool

IsDecimal(Type)

Returns true if T is decimal or nullable decimal

public static bool IsDecimal(this Type T)

Parameters

T Type

Returns

bool

IsDouble(Type)

Returns true if T is double or nullable double

public static bool IsDouble(this Type T)

Parameters

T Type

Returns

bool

IsFloat(Type)

Returns true if a specified type is float, double or decimal

public static bool IsFloat(this Type DataType)

Parameters

DataType Type

Returns

bool

IsInteger(Type)

Returns true if a specified type is an integer type, i.e. Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64

public static bool IsInteger(this Type DataType)

Parameters

DataType Type

Returns

bool

IsIntegerIndexer(PropertyInfo)

Returns true if the PropInfo is an one-dimensional integer indexer property

public static bool IsIntegerIndexer(PropertyInfo PropInfo)

Parameters

PropInfo PropertyInfo

Returns

bool

IsNullable(Type)

Returns true if T is of a Nullable type

public static bool IsNullable(this Type T)

Parameters

T Type

Returns

bool

IsNumeric(Type)

Returns true if a specified type is an integer or float type

public static bool IsNumeric(this Type DataType)

Parameters

DataType Type

Returns

bool

IsString(Type)

Returns true if a specified type is a string type

public static bool IsString(this Type DataType)

Parameters

DataType Type

Returns

bool