Class TypeExtensions
Static extension helper methods on Type.
Namespace: actionETL
Assembly: actionETL.dll
Syntax
public static class TypeExtensions
Methods
DisplayName(Type)
The display name of a type, which in several cases will be shorter and more readable than
Type.FullName.
Declaration
public static string DisplayName(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
Returns
| Type | Description | ||||||
|---|---|---|---|---|---|---|---|
| String | A type name, which in the following cases will be shortened:
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
GetFieldsAndPropertiesInOrder(Type, BindingFlags)
Gets the fields and properties of a single type, in a well defined order, either via reflection, or from a cache if the type has been queried previously.
Note that while this would include a member that is a struct, it would
not include the members inside that struct.
Also see TypeRowSchema, which does include columns in column schemas
(i.e. inside embedded struct members).
The order of the returned members is controlled with the OrderAttribute, using an ordering index:
OrderAttribute with index: The index is explicitly provided. It must be in the range:
[0, 9999], [20000,29999], [40000,49999], or [60000,69999].
OrderAttribute without index: The member will automatically get an index and be ordered on
the declaration order in the source file. This allows managing the order by simply moving the
members around in the row class. Base class members will come before derived class members, and for any
partial classes, the members are first sorted on the filename from
CallerFilePathAttribute. By default they will get an index
in the range [10000,19999], or in the range [50000,59999] if setting afterAlphabetical = true.
No OrderAttribute: These members will automatically get an index in the [30000,39999] range,
in member name (ordinal case sensitive) alphabetical order.
Declaration
public static IReadOnlyList<MemberInfo> GetFieldsAndPropertiesInOrder(this Type type, BindingFlags bindingFlags)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
| BindingFlags | bindingFlags | The binding flags that specifies which members to include. E.g. use
|
Returns
| Type | Description |
|---|---|
| IReadOnlyList<MemberInfo> | A MemberInfo readonly list with all matching fields and properties of the specified type, or an empty list if no matches found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
See Also
IsAssignableTo<T>(Type)
Determines whether an instance of a specified type can be assigned from the current type instance. It does the same check as IsAssignableFrom(Type), except the types have swapped places (and this one uses generics).
Declaration
public static bool IsAssignableTo<T>(this Type fromType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | fromType | The 'from' type to check. |
Returns
| Type | Description |
|---|---|
| Boolean |
false if none of these conditions are true, or if c is null.
|
Type Parameters
| Name | Description |
|---|---|
| T | The 'to' type to check. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
IsNullableType(Type)
Determines whether a type is nullable, e.g.
typeof(bool?).IsNullable() would return true.
Note: To check if a type is either a nullable value type or a reference type, use:
if (default(T) == null) ....
Declaration
public static bool IsNullableType(this Type theValueType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | theValueType | Type of the value. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|