Class Objects
Object manipulation functions.
Inherited Members
Namespace: TheXDS.MCART.Helpers
Assembly: MCART.dll
Syntax
public static class Objects
Methods
| Edit this page View SourceAreAllNull(params object?[])
Determines if all objects are null.
Declaration
public static bool AreAllNull(params object?[] collection)
Parameters
Type | Name | Description |
---|---|---|
object[] | collection | Objects to check. |
Returns
Type | Description |
---|---|
bool |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
FromBytes<T>(byte[])
Gets a value of type T
from a byte array
using marshaling.
Declaration
public static T FromBytes<T>(byte[] rawBytes) where T : struct
Parameters
Type | Name | Description |
---|---|---|
byte[] | rawBytes | Bytes to convert into the value. |
Returns
Type | Description |
---|---|
T | A value of type |
Type Parameters
Name | Description |
---|---|
T | Type of value to retrieve. Must be a structure. |
Remarks
Fields of type string in the structure must be decorated with:
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = <max size>)]
See Also
| Edit this page View SourceGetAttribute<T, TIt>()
Returns the attribute associated with the specified type declaration.
Declaration
public static T? GetAttribute<T, TIt>() where T : Attribute
Returns
Type | Description |
---|---|
T | An attribute of type |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit from Attribute. |
TIt | Type from which to extract the attribute. |
GetBytes<T>(T)
Gets a byte array from a value of type T
using marshaling.
Declaration
public static byte[] GetBytes<T>(T value) where T : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | Value to convert to bytes. |
Returns
Type | Description |
---|---|
byte[] | A byte array that can be used to reconstruct the value. |
Type Parameters
Name | Description |
---|---|
T | Type of value to convert to bytes. |
Remarks
Fields of type string in the structure must be decorated with:
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = <max size>)]
See Also
| Edit this page View SourceIsAnyNull(params object?[])
Determines if any of the objects is null.
Declaration
public static bool IsAnyNull(params object?[] x)
Parameters
Type | Name | Description |
---|---|---|
object[] | x | Objects to check. |
Returns
Type | Description |
---|---|
bool |
Itself<T>(T)
Returns a circular reference to this object.
Declaration
public static T Itself<T>(this T obj)
Parameters
Type | Name | Description |
---|---|---|
T | obj | Object. |
Returns
Type | Description |
---|---|
T | This object. |
Type Parameters
Name | Description |
---|---|
T | Type of this object. |
Remarks
This function is only useful when using Visual Basic with the
With
structure.
ShallowClone<T>(T)
Creates a new copy of the object.
Declaration
public static T ShallowClone<T>(this T source) where T : notnull, new()
Parameters
Type | Name | Description |
---|---|---|
T | source | Source object. |
Returns
Type | Description |
---|---|
T | A new instance of type |
Type Parameters
Name | Description |
---|---|
T | Type of object to clone. |
ShallowCopyTo(object, object, Type)
Copies the property values from one object to another.
Declaration
public static void ShallowCopyTo(this object source, object destination, Type objectType)
Parameters
Type | Name | Description |
---|---|---|
object | source | Source object. |
object | destination | Destination object. |
Type | objectType | Type of objects to copy. Limits the copy to properties and fields accessible within the specified type. |
ShallowCopyTo<T>(T, T)
Copies the property values from one object to another.
Declaration
public static void ShallowCopyTo<T>(this T source, T destination) where T : notnull
Parameters
Type | Name | Description |
---|---|---|
T | source | Source object. |
T | destination | Destination object. |
Type Parameters
Name | Description |
---|---|
T | Type of objects to operate on. |
ToTypes(params object[])
Gets a list of the types of the specified objects.
Declaration
public static IEnumerable<Type> ToTypes(params object[] objects)
Parameters
Type | Name | Description |
---|---|---|
object[] | objects | Objects to generate the type collection from. |
Returns
Type | Description |
---|---|
IEnumerable<Type> | A list of the types of the provided objects. |
TryCreateDelegate<T>(MethodInfo, object, out T?)
Encapsulates CreateDelegate(Type, object, string, bool, bool) to ensure all possible exceptions are caught.
Declaration
public static bool TryCreateDelegate<T>(MethodInfo method, object instance, out T? @delegate) where T : notnull, Delegate
Parameters
Type | Name | Description |
---|---|---|
MethodInfo | method | Method to create the delegate from. |
object | instance | Instance to bind the delegate to. |
T | delegate | Created delegate. null if the delegate could not be created. |
Returns
Type | Description |
---|---|
bool | true if the delegate was successfully created; otherwise, false. |
Type Parameters
Name | Description |
---|---|
T | Type of delegate to create. |
Remarks
This method was created due to a quirk in CreateDelegate(Type, object, string, bool, bool), where it may still throw an exception if the method contains generic parameters.
TryCreateDelegate<T>(MethodInfo, out T?)
Safe version of CreateDelegate(Type, MethodInfo, bool).
Declaration
public static bool TryCreateDelegate<T>(MethodInfo method, out T? @delegate) where T : notnull, Delegate
Parameters
Type | Name | Description |
---|---|---|
MethodInfo | method | Method to create the delegate from. |
T | delegate | Created delegate. null if the delegate could not be created. |
Returns
Type | Description |
---|---|
bool | true if the delegate was successfully created; otherwise, false. |
Type Parameters
Name | Description |
---|---|
T | Type of delegate to create. |
Remarks
This method was created due to a quirk in CreateDelegate(Type, MethodInfo, bool), where it may still throw an exception if the method contains generic parameters.
WhichAreNull(params object?[])
Determines which objects are null.
Declaration
public static IEnumerable<int> WhichAreNull(params object?[] collection)
Parameters
Type | Name | Description |
---|---|---|
object[] | collection | Collection of objects to check. |
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerator with the indices of objects that are null. |