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
ClassTypeType
Returns
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
Returns
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
Returns
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
Returns
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
Returns
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
ClassTypeType
Returns
FindPublicProperty(Type, string)
Finds the public instance property of ClassType by PropertyName
public static PropertyInfo FindPublicProperty(this Type ClassType, string PropertyName)
Parameters
Returns
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
Argsobject[]
Returns
- Type[]
GetDefaultFormat(Type)
Returns the default format string for the specified type.
public static string GetDefaultFormat(this Type T)
Parameters
TType
Returns
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
Returns
GetPublicPropertyValue(object, string)
Returns the value of the public property PropertyName, if any, else null.
public static object GetPublicPropertyValue(object Instance, string PropertyName)
Parameters
Returns
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
Returns
HasDefaultConstructor(Type)
Returns true if a type defines a default public constructor
public static bool HasDefaultConstructor(this Type ClassType)
Parameters
ClassTypeType
Returns
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
Returns
ImplementsInterface(Type, Type)
Returns true if ClassType implements InterfaceType.
public static bool ImplementsInterface(this Type ClassType, Type InterfaceType)
Parameters
Returns
ImplementsInterfaces(Type, Type[])
Returns true if ClassType implements all InterfaceTypes.
public static bool ImplementsInterfaces(this Type ClassType, Type[] InterfaceTypes)
Parameters
Returns
InheritsFrom(object, Type)
Returns true if Instance is a or inherits from Value.
public static bool InheritsFrom(this object Instance, Type Value)
Parameters
Returns
InheritsFrom(Type, Type)
Returns true if ClassType is a or inherits from Value.
public static bool InheritsFrom(this Type ClassType, Type Value)
Parameters
Returns
IsDateTime(Type)
Returns true if a specified type is a DateTime type
public static bool IsDateTime(this Type DataType)
Parameters
DataTypeType
Returns
IsDecimal(Type)
Returns true if T is decimal or nullable decimal
public static bool IsDecimal(this Type T)
Parameters
TType
Returns
IsDouble(Type)
Returns true if T is double or nullable double
public static bool IsDouble(this Type T)
Parameters
TType
Returns
IsFloat(Type)
Returns true if a specified type is float, double or decimal
public static bool IsFloat(this Type DataType)
Parameters
DataTypeType
Returns
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
DataTypeType
Returns
IsIntegerIndexer(PropertyInfo)
Returns true if the PropInfo is an one-dimensional integer indexer property
public static bool IsIntegerIndexer(PropertyInfo PropInfo)
Parameters
PropInfoPropertyInfo
Returns
IsNullable(Type)
Returns true if T is of a Nullable type
public static bool IsNullable(this Type T)
Parameters
TType
Returns
IsNumeric(Type)
Returns true if a specified type is an integer or float type
public static bool IsNumeric(this Type DataType)
Parameters
DataTypeType
Returns
IsString(Type)
Returns true if a specified type is a string type
public static bool IsString(this Type DataType)
Parameters
DataTypeType