Show / Hide Table of Contents

Class ObjectExtensions

Contains useful extensions for the object class.

Inheritance
object
ObjectExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.dll
Syntax
public static class ObjectExtensions

Methods

| Edit this page View Source

FieldsOf<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 T of the object.

Type Parameters
Name Description
T

Type of fields to obtain.

Exceptions
Type Condition
ArgumentNullException

Thrown if instance is null.

| Edit this page View Source

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 T with the associated data in the object's declaration; or null if the specified attribute is not found.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit from Attribute.

| Edit this page View Source

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 T with the associated data in the assembly declaration; or null in case of not finding the specified attribute.

Type Parameters
Name Description
T

Type of attribute to return. Must inherit from Attribute.

| Edit this page View Source

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 TAttribute has been found, the value of the same is returned. Default will be returned if the member does not possess the specified attribute.

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.

| Edit this page View Source

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.

| Edit this page View Source

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 T has been found, the same is returned. Null will be returned if the member does not possess the specified attribute.

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.

| Edit this page View Source

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 T has been found, the same is returned. Null will be returned if the member does not possess the attribute specified.

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.

| Edit this page View Source

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 obj1 is the same as obj2, false otherwise.

| Edit this page View Source

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 obj is any of the specified objects, false otherwise.

| Edit this page View Source

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 obj is any of the specified objects, false otherwise.

| Edit this page View Source

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 obj is not any of the specified objects, false otherwise.

| Edit this page View Source

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 obj is not any of the specified objects, false otherwise.

| Edit this page View Source

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 obj1 is not the same as obj2, false otherwise.

| Edit this page View Source

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 T of the object.

Type Parameters
Name Description
T

Type of properties to obtain.

| Edit this page View Source

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 obj.

| Edit this page View Source

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 obj.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX