Class TypeHelper
Utility/Extension class to assist analysis of data-types when doing reflection-code.
Inherited Members
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public static class TypeHelper
Methods
CreateDefaultEntity(Type)
Safely creates a default-value for the specified type.
Declaration
public static object CreateDefaultEntity(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type |
Returns
| Type | Description |
|---|---|
| object |
GetAllInterfaces(Type)
Gets all interfaces implemented by the type. This may includes the type itself it if itself is an interface.
Declaration
public static Type[] GetAllInterfaces(this Type instance)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance |
Returns
| Type | Description |
|---|---|
| Type[] |
GetPublicReadableProperties(Type)
Gets the public, readable instance-properties of a type.
Declaration
public static IEnumerable<PropertyInfo> GetPublicReadableProperties(this Type instance)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyze. |
Returns
| Type | Description |
|---|---|
| IEnumerable<PropertyInfo> | Empty array if no properties found. |
IsComplex(Type)
Determines if the type represents a complex type.
Declaration
public static bool IsComplex(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to analyze. |
Returns
| Type | Description |
|---|---|
| bool | true is complex. |
IsDecimalNumber(Type)
Determins if the type represents a type which can represent decimal nubers.
Declaration
public static bool IsDecimalNumber(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to analyze. |
Returns
| Type | Description |
|---|---|
| bool | true if decimal number |
IsDictionary(Type, out Type, out Type)
Checks is the instance repesent an generic dictionary and attempts to discover the types used for its key/value-pairs.
Declaration
public static bool IsDictionary(this Type instance, out Type keyType, out Type valueType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
| Type | keyType | The key-type in the dictionary. Set to null if result type isn't a dictionary. |
| Type | valueType | The value-type in the dictionary. Set to null if result type isn't a dictionary. |
Returns
| Type | Description |
|---|---|
| bool | true if a dictionary. |
IsEnumerable(Type)
Checks if the instance represents an enumerable type.
Declaration
public static bool IsEnumerable(this Type instance)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
Returns
| Type | Description |
|---|---|
| bool | true if enumerable. |
IsEnumerable(Type, out Type)
Checks if the instance represents an enumerable type and attempts to
discover the type it enumerates over.
Declaration
public static bool IsEnumerable(this Type instance, out Type elementType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
| Type | elementType | The type which the enumerable contains. Set to null if result type is unenumerable. |
Returns
| Type | Description |
|---|---|
| bool | true if enumerable. |
IsGenericEnumerable(Type, out Type)
Checks is the instance repesent an generic enemurable and attempts to discover the type it enumerates over.
Declaration
public static bool IsGenericEnumerable(this Type instance, out Type elementType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
| Type | elementType | The type which the enumerable contains. Set to null if result type is unenumerable. |
Returns
| Type | Description |
|---|---|
| bool | true if enumerable. |
IsGenericIDictionary(Type, out Type, out Type)
Checks is the instance repesent an generic dictionary and attempts to discover the types used for its key/value-pairs.
Declaration
public static bool IsGenericIDictionary(this Type instance, out Type keyType, out Type valueType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
| Type | keyType | The key-type in the dictionary. Set to null if result type isn't a dictionary. |
| Type | valueType | The value-type in the dictionary. Set to null if result type isn't a dictionary. |
Returns
| Type | Description |
|---|---|
| bool | true if a dictionary. |
IsGenericIList(Type, out Type)
Checks is the instance repesent an generic List and attempts to discover the type it enumerates over.
Declaration
public static bool IsGenericIList(this Type instance, out Type elementType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
| Type | elementType | The type which the enumerable contains. Set to null if result type is unenumerable. |
Returns
| Type | Description |
|---|---|
| bool | true if generic List. |
IsNonGenericIDictionary(Type)
Checks is the instance repesent an non-generic dictionary.
Declaration
public static bool IsNonGenericIDictionary(this Type instance)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
Returns
| Type | Description |
|---|---|
| bool | true if a dictionary. |
IsNongenericEnumerable(Type)
Checks is the instance repesent an non-generic IEnumerable.
Declaration
public static bool IsNongenericEnumerable(this Type instance)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
Returns
| Type | Description |
|---|---|
| bool | true if nongeneric IEnumerable. |
IsNongenericIList(Type)
Checks is the instance repesent an non-generic IList.
Declaration
public static bool IsNongenericIList(this Type instance)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | instance | The type to analyse |
Returns
| Type | Description |
|---|---|
| bool | true if nongeneric IList. |
IsNullable(Type)
Determines if the provided type is a Nullable one.
Declaration
public static bool IsNullable(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type |
Returns
| Type | Description |
|---|---|
| bool |
IsSimple(Type)
Determines if the type represents a simple/primitive type.
Declaration
public static bool IsSimple(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to analyze. |
Returns
| Type | Description |
|---|---|
| bool | true if simple |