Class ObjectExtensions
Contains useful extensions for the object class.
Inherited Members
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class ObjectExtensions
Methods
| Edit this page View SourceFieldsOf<T>(object)
Enumerates the value of all fields that return values of
type T
of the specified object.
Declaration
public static IEnumerable<T> FieldsOf<T>(this object instance)
Parameters
Type | Name | Description |
---|---|---|
object | instance | Instance from which to obtain the fields. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all values of type
|
Type Parameters
Name | Description |
---|---|
T | Type of fields to obtain. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
GetAttribute<T>(object)
Retrieves the attribute associated with the declaration of the specified object.
Declaration
public static T? GetAttribute<T>(this object obj) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object from which the attribute will be extracted. |
Returns
Type | Description |
---|---|
T | An attribute of the type |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit from Attribute. |
GetAttributes<T>(object)
Returns the attribute associated with the specified assembly.
Declaration
public static IEnumerable<T>? GetAttributes<T>(this object member) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
object | member | object from which the attribute will be extracted. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An attribute of the type |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit from Attribute. |
HasAttrValue<TAttribute, TValue>(object, out TValue)
Determines if a member possesses an attribute defined.
Declaration
public static bool HasAttrValue<TAttribute, TValue>(this object obj, out TValue value) where TAttribute : Attribute, IValueAttribute<TValue>
Parameters
Type | Name | Description |
---|---|---|
object | obj | Member from which the attribute will be extracted. |
TValue | value | Out parameter. If an attribute of type
|
Returns
Type | Description |
---|---|
bool | true if the member possesses the attribute, false otherwise. |
Type Parameters
Name | Description |
---|---|
TAttribute | Type of attribute to search for. Must inherit from Attribute and from IValueAttribute<T>. |
TValue | Type of value to return. |
HasAttribute<T>(object)
Determines if a member possesses an attribute defined.
Declaration
public static bool HasAttribute<T>(this object obj) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
object | obj | Member from which the attribute will be extracted. |
Returns
Type | Description |
---|---|
bool | true if the member possesses the attribute, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit from Attribute. |
HasAttribute<T>(object, out T?)
Determines if a member possesses an attribute defined.
Declaration
public static bool HasAttribute<T>(this object obj, out T? attribute) where T : notnull, Attribute
Parameters
Type | Name | Description |
---|---|---|
object | obj | Member from which the attribute will be extracted. |
T | attribute | Out parameter. If an attribute of type
|
Returns
Type | Description |
---|---|
bool | true if the member possesses the attribute, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit from Attribute. |
HasAttributes<T>(object, out IEnumerable<T>?)
Determines if a member possesses an attribute defined.
Declaration
public static bool HasAttributes<T>(this object obj, out IEnumerable<T>? attribute) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
object | obj | Member from which the attribute will be extracted. |
IEnumerable<T> | attribute | Out parameter. If an attribute of type
|
Returns
Type | Description |
---|---|
bool | true if the member possesses the attribute, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | Type of attribute to return. Must inherit from Attribute. |
Is(object?, object?)
Determines if obj1
is the same instance as
obj2
.
Declaration
public static bool Is(this object? obj1, object? obj2)
Parameters
Type | Name | Description |
---|---|---|
object | obj1 | Object to check. |
object | obj2 | Object against which to compare. |
Returns
Type | Description |
---|---|
bool | true if the instance of |
IsEither(object, IEnumerable)
Determines if an object is any of the specified ones.
Declaration
public static bool IsEither(this object obj, IEnumerable objects)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object to check. |
IEnumerable | objects | List of objects to compare. |
Returns
Type | Description |
---|---|
bool | true if |
IsEither(object, params object[])
Determines if an object is any of the specified ones.
Declaration
public static bool IsEither(this object obj, params object[] objects)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object to check. |
object[] | objects | List of objects to compare. |
Returns
Type | Description |
---|---|
bool | true if |
IsNeither(object, IEnumerable)
Determines if an object is not any of the specified ones.
Declaration
public static bool IsNeither(this object obj, IEnumerable objects)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object to check. |
IEnumerable | objects | List of objects to compare. |
Returns
Type | Description |
---|---|
bool | true if |
IsNeither(object, params object[])
Determines if an object is not any of the specified ones.
Declaration
public static bool IsNeither(this object obj, params object[] objects)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object to check. |
object[] | objects | List of objects to compare. |
Returns
Type | Description |
---|---|
bool | true if |
IsNot(object?, object?)
Determines if obj1
is a different instance than
obj2
.
Declaration
public static bool IsNot(this object? obj1, object? obj2)
Parameters
Type | Name | Description |
---|---|---|
object | obj1 | Object to check. |
object | obj2 | Object against which to compare. |
Returns
Type | Description |
---|---|
bool | true if the instance of |
PropertiesOf<T>(object)
Enumerates the value of all properties that return values of
type T
of the specified object.
Declaration
public static IEnumerable<T> PropertiesOf<T>(this object instance)
Parameters
Type | Name | Description |
---|---|---|
object | instance | Instance from which to obtain the properties. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration of all values of type
|
Type Parameters
Name | Description |
---|---|
T | Type of properties to obtain. |
WhichAre(object, IEnumerable<object>)
Determines if any of the objects are the same instance as
obj
.
Declaration
public static IEnumerable<int> WhichAre(this object obj, IEnumerable<object> collection)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object to check. |
IEnumerable<object> | collection | Collection of objects to check. |
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerator with the indices of the objects that are the same
instance as |
WhichAre(object, params object[])
Determines if any of the objects are the same instance as
obj
.
Declaration
public static IEnumerable<int> WhichAre(this object obj, params object[] collection)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object to check. |
object[] | collection | Collection of objects to check. |
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerator with the indices of the objects that are the same
instance as |