Class ReflectionExtensions
Provides various extension methods for Reflection and Types.
Inherited Members
Namespace: Swan
Syntax
public static class ReflectionExtensions
Methods
GetAllTypes(Assembly)
Gets all types within an assembly in a safe manner.
Declaration
public static IEnumerable<Type> GetAllTypes(this Assembly assembly)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | assembly | The assembly. |
Returns
| Type | Description |
|---|---|
| IEnumerable<Type> | Array of Type objects representing the types specified by an assembly. |
GetDefault(Type)
The closest programmatic equivalent of default(T).
Declaration
public static object GetDefault(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
Returns
| Type | Description |
|---|---|
| Object | Default value of this type. |
GetMethod(Type, BindingFlags, String, Type[], Type[])
Gets a method from a type given the method name, binding flags, generic types and parameter types.
Declaration
public static MethodInfo GetMethod(this Type type, BindingFlags bindingFlags, string methodName, Type[] genericTypes, Type[] parameterTypes)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | Type of the source. |
| BindingFlags | bindingFlags | The binding flags. |
| String | methodName | Name of the method. |
| Type[] | genericTypes | The generic types. |
| Type[] | parameterTypes | The parameter types. |
Returns
| Type | Description |
|---|---|
| MethodInfo | An object that represents the method with the specified name. |
Exceptions
| Type | Condition |
|---|---|
| AmbiguousMatchException | The exception that is thrown when binding to a member results in more than one member matching the binding criteria. This class cannot be inherited. |
IsCollection(Type)
Determines whether this type is compatible with ICollection.
Declaration
public static bool IsCollection(this Type sourceType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | sourceType | The type. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
IsIEnumerable(Type)
Determines whether [is i enumerable request].
Declaration
public static bool IsIEnumerable(this Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
ToBoolean(Object)
Convert a object to a boolean.
Declaration
public static bool ToBoolean(this object value)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | value | The value. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
ToBoolean(String)
Convert a string to a boolean.
Declaration
public static bool ToBoolean(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| String | str | The string. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
TryParseBasicType(Type, Object, out Object)
Tries to parse using the basic types.
Declaration
public static bool TryParseBasicType(this Type type, object value, out object result)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
| Object | value | The value. |
| Object | result | The result. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
TryParseBasicType(Type, String, out Object)
Tries to parse using the basic types.
Declaration
public static bool TryParseBasicType(this Type type, string value, out object result)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
| String | value | The value. |
| Object | result | The result. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
TrySetArray(PropertyInfo, Nullable<IEnumerable<Object>>, Object)
Tries to set a property array with another array.
Declaration
public static bool TrySetArray(this PropertyInfo propertyInfo, IEnumerable<object>? value, object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| PropertyInfo | propertyInfo | The property. |
| Nullable<IEnumerable<Object>> | value | The value. |
| Object | obj | The object. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
TrySetArrayBasicType(Type, Object, Array, Int32)
Tries the type of the set to an array a basic type.
Declaration
public static bool TrySetArrayBasicType(this Type type, object value, Array target, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type. |
| Object | value | The value. |
| Array | target | The array. |
| Int32 | index | The index. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
TrySetBasicType(PropertyInfo, Object, Object)
Tries the type of the set basic value to a property.
Declaration
public static bool TrySetBasicType(this PropertyInfo propertyInfo, object value, object target)
Parameters
| Type | Name | Description |
|---|---|---|
| PropertyInfo | propertyInfo | The property information. |
| Object | value | The value. |
| Object | target | The object. |
Returns
| Type | Description |
|---|---|
| Boolean |
|