PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.ObjectExtensions Class Reference

Provides a set of convenience extensions on everything. More...

Static Public Member Functions

static bool DeepEquals (this object objSource, object objCompare, params string[] ignorePropertiesByName)
 Runs a deep equality test between two objects, glossing over reference differences between class-types and comparing only primitive types. Use this when you'd like to essentially test whether the data in one object hierarchy matches that of another.
static bool ShapeEquals (this object objSource, object objCompare, params string[] ignorePropertiesByName)
 Tests if two objects have the same "shape" – basically Deep Equality testing without actually testing final property values.
static bool ShapeSubEquals (this object objSource, object objCompare, params string[] ignorePropertiesByName)
 Tests if a second object has at least the "shape" of a primary one. Basically a DeepSubEquals without testing final property values. without actually testing final property values.
static bool DeepEquals (this object objSource, object objCompare, ObjectComparisons comparison, params string[] ignorePropertiesByName)
 Runs a deep equality test between two objects, glossing over reference differences between class-types and comparing only primitive types. Use this when you'd like to essentially test whether the data in one object hierarchy matches that of another.
static bool DeepEquals (this object objSource, object objCompare, Action< string > failureLogAction, params string[] ignorePropertiesByName)
 Runs a deep equality test between two objects, ignoring reference differences wherever possible and logging failures with the provided action. Properties can be excluded by name with the ignorePropertiesByName params.
static bool DeepSubEquals (this object objSource, object objCompare, params string[] ignorePropertiesByName)
 Runs a deep equality test between two objects, using the properties on objSource (and children) as the set of properties to match on.
static bool DeepIntersectionEquals (this object objSource, object objCompare, params string[] ignorePropertiesByName)
 Runs a deep equality test between two objects, using the properties common to both sides of the comparison to match on.
static bool ContainsAtLeastOneDeepEqualTo< T1, T2 > (this IEnumerable< T1 > collection, T2 item, params string[] ignoreProperties)
 Searches a collection for one or more objects which DeepEquals the provided reference item.
static bool ContainsOneDeepEqualTo< T1, T2 > (this IEnumerable< T1 > collection, T2 item, params string[] ignoreProperties)
 Searches a collection for a single object which DeepEquals the provided reference item.
static bool ContainsOneIntersectionEqualTo< T1, T2 > (this IEnumerable< T1 > collection, T2 item, params string[] ignoreProperties)
 Searches a collection for an object which IntersectionEquals the provided reference item.
static bool ContainsOnlyOneDeepEqualTo< T1, T2 > (this IEnumerable< T1 > collection, T2 item, params string[] ignoreProperties)
 Searches a collection for an object which DeepEquals the provided reference item.
static bool ContainsOnlyOneIntersectionEqualTo< T1, T2 > (this IEnumerable< T1 > collection, T2 item, params string[] ignoreProperties)
 Searches a collection for an object which IntersectionEquals the provided reference item.
static bool ContainsOnlyOneMatching< T1, T2 > (this IEnumerable< T1 > collection, T2 item, Func< T1, T2, bool > comparer)
 Searches a collection for an object which matches the provided reference item, according to the provided matcher Func.
static T CopyPropertiesTo< T > (this object src, T dst)
 Copies all public primitive property values of intersecting properties from the source object to the target object, ala poor-man's AutoMapper.
static T CopyPropertiesTo< T > (this object src, T dst, params string[] ignoreProperties)
 Copies all public primitive property values of intersecting properties from the source object to the target object, ala poor-man's AutoMapper.
static T CopyPropertiesTo< T > (this object src, T dst, bool deep, params string[] ignoreProperties)
 Copies all public primitive property values of intersecting properties from the source object to the target object, ala poor-man's AutoMapper.
static T DeepClone< T > (this T item)
 Creates a deep clone of the provided item, as far as possible Works on properties which are:
static T Get< T > (this object src, string propertyPath)
 Gets the value of a property on an object, specified by the property path, of the given Type.
static object Get (this object src, string propertyPath, Type type)
 Provides a non-generic interface to Get<T>.
static T GetOrDefault< T > (this object src, string propertyPath)
 Gets the value of a property on an object, specified by the property path, of the given Type or returns a default value when that property cannot be found by path and/or type.
static T GetOrDefault< T > (this object src, string propertyPath, T defaultValue)
 Gets the value of a property on an object, specified by the property path, of the given Type or returns a default value when that property cannot be found by path and/or type.
static T[] AsArray< T > (this T input)
 Fluency extension to wrap a single item in an array, eg: new SomeBusinessObject().AsArray().Union(SomeOtherCollection);.
static T[] InArray< T > (this T input)
 Fluency extension to wrap a single item in an array, eg: new SomeBusinessObject().InArray().Union(SomeOtherCollection);.
static List< T > InList< T > (this T input)
 Fluency extension to wrap a single item in a list, eg: new SomeBusinessObject().InList().Union(SomeOtherCollection);.
static object GetPropertyValue (this object src, string propertyPath)
 Gets a property value by name from an object.
static object InvokeMethodWithResult (this object src, string methodName, params object[] args)
 Invokes a method on an object, if available; otherwise explodes.
static void SetPropertyValue (this object src, string propertyPath, object newValue)
 Attempts to set a property value on an object by property path.
static void Set< T > (this object src, string propertyPath, T newValue)
 Attempts to set a property value on an object by property path.
static bool TrySet< T > (this object src, string propertyPath, T newValue)
 attempts to set a property value on an object by path and value
static T GetPropertyValue< T > (this object src, string propertyPath)
 Gets an immediate property value, cast to the specified type.
static bool IsAssignableTo< T > (this Type type)
 Tests if a type is assignable to another type (inverse of IsAssignableFrom)
static decimal TruncateTo (this decimal value, int places)
 Truncates a decimal value to a required number of places.
static double TruncateTo (this double value, int places)
 Truncates a decimal value to a required number of places.
static decimal ToFixed (this decimal value, int places)
 Provides a similar api to Javascript's .toFixed(), except returning a useful decimal! Note: this is different from .TruncateTo since that will truncate the value, whereas this will round.
static double ToFixed (this double value, int places)
 Provides a similar api to Javascript's .toFixed(), except returning a useful double! Note: this is different from .TruncateTo since that will truncate the value, whereas this will round.
static IEnumerable< T > AsEnumerable< T > (this object src)
 Attempts to convert any object to an IEnumerable<T>.
static bool TryChangeType< T > (this object input, out T output)
 Analogous to TryParse methods, this will attempt to convert a value to the type T, returning true if it can, and populating the output parameter.
static bool TryChangeType (this object input, Type requiredType, out object output)
 Analogous to TryParse methods, this will attempt to convert a value to the type requiredType, returning true if it can, and populating the output parameter.
static bool IsInstanceOf< T > (this object obj)
 Tests if the given object is an instance of the type T.
static bool IsInstanceOf (this object obj, Type type)
 Tests if the given object is an instance of the provided type.
static bool IsRuntimeType (this object obj)
 Determines whether or not an arbitrary object is a RuntimeType.
static bool HasProperty (this object obj, string prop)
 Tests if the object has the requested property by path.
static bool HasProperty< T > (this object obj, string prop)
 Tests whether the object has the named property with the type T.
static bool HasProperty (this object obj, string prop, Type propertyType)
 Tests if the object has the named property with the expected type.
static bool TryGet< T > (this object obj, string propertyPath, out T result)
 Attempt to retrieve the named property with the given type off of the provided object.
static bool Is (this object original, object test)
 Tests if two objects are the same reference in memory (ie, short-hand for object.ReferenceEquals(original, test);.
static IDictionary< TKey, TValue > AsDictionary< TKey, TValue > (this object obj)
 Attempts to provide a dictionary representation for the provided object. If the provided object already implements IDictionary<TKey, TValue> then you'll get the same instance back - be careful to clone it if you don't want to mutate the original.
static IDictionary< string, string > AsDictionary< T > (this T value, Func< T, IEnumerable< string > > keyFetcher, Func< T, string, string > valueFetcher)
 Produces a string-string dictionary from any value, given that value and two funcs:
static T DeserializeFromJson< T > (this string json)
 Deserializes a json string to the type T, by first figuring out if T's properties are decorated for System.Text.Json or Newtonsoft.Json and then choosing the serializer accordingly.
static string SerializeToJson< T > (this T item)
 Serializes an object of type T to json, by first figuring out if T's properties are decorated for System.Text.Json or Newtonsoft.Json and then choosing the serializer accordingly.

Detailed Description

Provides a set of convenience extensions on everything.

Member Function Documentation

◆ AsArray< T >()

T[] PeanutButter.Utils.ObjectExtensions.AsArray< T > ( this T input)
static

Fluency extension to wrap a single item in an array, eg: new SomeBusinessObject().AsArray().Union(SomeOtherCollection);.

Parameters
inputThe item to wrap
Template Parameters
TThe type of the object
Returns
A single-element array containing the input object

◆ AsDictionary< T >()

IDictionary< string, string > PeanutButter.Utils.ObjectExtensions.AsDictionary< T > ( this T value,
Func< T, IEnumerable< string > > keyFetcher,
Func< T, string, string > valueFetcher )
static

Produces a string-string dictionary from any value, given that value and two funcs:

  • one to retrieve all keys on the object
  • one to resolve a key to a value for the object
Parameters
value
keyFetcher
valueFetcher
Template Parameters
T
Returns

◆ AsDictionary< TKey, TValue >()

IDictionary< TKey, TValue > PeanutButter.Utils.ObjectExtensions.AsDictionary< TKey, TValue > ( this object obj)
static

Attempts to provide a dictionary representation for the provided object. If the provided object already implements IDictionary<TKey, TValue> then you'll get the same instance back - be careful to clone it if you don't want to mutate the original.

Parameters
obj
Returns
Exceptions
NotSupportedException

◆ AsEnumerable< T >()

IEnumerable< T > PeanutButter.Utils.ObjectExtensions.AsEnumerable< T > ( this object src)
static

Attempts to convert any object to an IEnumerable<T>.

  • existing IEnumerables will "just work"
  • where possible, types are cast or converted
    • eg an array of strings which are numbers will be converted to ints if required
  • also deals with objects which don't implement IEnumerable, but are enumerable in a foreach as per C#/.NET compile-time duck-typing, like Regex's MatchCollection
Parameters
srcObject to operate on
Template Parameters
TDesired collection element type
Returns

◆ ContainsAtLeastOneDeepEqualTo< T1, T2 >()

bool PeanutButter.Utils.ObjectExtensions.ContainsAtLeastOneDeepEqualTo< T1, T2 > ( this IEnumerable< T1 > collection,
T2 item,
params string[] ignoreProperties )
static

Searches a collection for one or more objects which DeepEquals the provided reference item.

Parameters
collectionCollection of objects to search
itemItem to find a match for
ignorePropertiesOptional params array of properties to ignore by name
Template Parameters
T1Item type of the collection
T2Type of the comparison item (can be the same as or different from T1)
Returns
True if one or more matching objects were found; false otherwise

◆ ContainsOneDeepEqualTo< T1, T2 >()

bool PeanutButter.Utils.ObjectExtensions.ContainsOneDeepEqualTo< T1, T2 > ( this IEnumerable< T1 > collection,
T2 item,
params string[] ignoreProperties )
static

Searches a collection for a single object which DeepEquals the provided reference item.

Parameters
collectionCollection of objects to search
itemItem to find a match for
ignorePropertiesOptional params array of properties to ignore by name
Template Parameters
T1Item type of the collection
T2Type of the comparison item (can be the same as or different from T1)
Returns
True if one or more matching objects were found; false otherwise

◆ ContainsOneIntersectionEqualTo< T1, T2 >()

bool PeanutButter.Utils.ObjectExtensions.ContainsOneIntersectionEqualTo< T1, T2 > ( this IEnumerable< T1 > collection,
T2 item,
params string[] ignoreProperties )
static

Searches a collection for an object which IntersectionEquals the provided reference item.

Parameters
collectionCollection of objects to search
itemItem to find a match for
ignorePropertiesOptional params array of properties to ignore by name
Template Parameters
T1Item type of the collection
T2Type of the comparison item (can be the same as or different from T1)
Returns
True if one or more matching objects were found; false otherwise

◆ ContainsOnlyOneDeepEqualTo< T1, T2 >()

bool PeanutButter.Utils.ObjectExtensions.ContainsOnlyOneDeepEqualTo< T1, T2 > ( this IEnumerable< T1 > collection,
T2 item,
params string[] ignoreProperties )
static

Searches a collection for an object which DeepEquals the provided reference item.

Parameters
collectionCollection of objects to search
itemItem to find a match for
ignorePropertiesOptional params array of properties to ignore by name
Template Parameters
T1Item type of the collection
T2Type of the comparison item (can be the same as or different from T1)
Returns
True if exactly one matching object was found; false otherwise

◆ ContainsOnlyOneIntersectionEqualTo< T1, T2 >()

bool PeanutButter.Utils.ObjectExtensions.ContainsOnlyOneIntersectionEqualTo< T1, T2 > ( this IEnumerable< T1 > collection,
T2 item,
params string[] ignoreProperties )
static

Searches a collection for an object which IntersectionEquals the provided reference item.

Parameters
collectionCollection of objects to search
itemItem to find a match for
ignorePropertiesOptional params array of properties to ignore by name
Template Parameters
T1Item type of the collection
T2Type of the comparison item (can be the same as or different from T1)
Returns
True if exactly one matching object was found; false otherwise

◆ ContainsOnlyOneMatching< T1, T2 >()

bool PeanutButter.Utils.ObjectExtensions.ContainsOnlyOneMatching< T1, T2 > ( this IEnumerable< T1 > collection,
T2 item,
Func< T1, T2, bool > comparer )
static

Searches a collection for an object which matches the provided reference item, according to the provided matcher Func.

Parameters
collectionCollection of objects to search
itemItem to find a match for
comparerFunc to use to perform comparison
Template Parameters
T1Item type of the collection
T2Type of the comparison item (can be the same as or different from T1)
Returns
True if exactly one matching object was found; false otherwise

◆ CopyPropertiesTo< T >() [1/3]

T PeanutButter.Utils.ObjectExtensions.CopyPropertiesTo< T > ( this object src,
T dst )
static

Copies all public primitive property values of intersecting properties from the source object to the target object, ala poor-man's AutoMapper.

Parameters
srcSource object
dstTarget object

◆ CopyPropertiesTo< T >() [2/3]

T PeanutButter.Utils.ObjectExtensions.CopyPropertiesTo< T > ( this object src,
T dst,
bool deep,
params string[] ignoreProperties )
static

Copies all public primitive property values of intersecting properties from the source object to the target object, ala poor-man's AutoMapper.

Parameters
srcSource object
dstTarget object
deepFlag: whether the process should copy deep (ie, traverse into child objects)
ignoreProperties

◆ CopyPropertiesTo< T >() [3/3]

T PeanutButter.Utils.ObjectExtensions.CopyPropertiesTo< T > ( this object src,
T dst,
params string[] ignoreProperties )
static

Copies all public primitive property values of intersecting properties from the source object to the target object, ala poor-man's AutoMapper.

Parameters
srcSource object
dstTarget object
ignorePropertiesOptional list of properties to ignore by name

◆ DeepClone< T >()

T PeanutButter.Utils.ObjectExtensions.DeepClone< T > ( this T item)
static

Creates a deep clone of the provided item, as far as possible Works on properties which are:

  • simple values,
  • any complex, non-generic value with a parameterless constructor
  • Collections which are arrays, generic IEnumerable or generic List, conforming to the rules above
Parameters
itemItem to clone
Template Parameters
TType of the item to clone
Returns
a new copy of the original item

◆ DeepEquals() [1/3]

bool PeanutButter.Utils.ObjectExtensions.DeepEquals ( this object objSource,
object objCompare,
Action< string > failureLogAction,
params string[] ignorePropertiesByName )
static

Runs a deep equality test between two objects, ignoring reference differences wherever possible and logging failures with the provided action. Properties can be excluded by name with the ignorePropertiesByName params.

Parameters
objSource
objCompare
failureLogAction
ignorePropertiesByName
Returns

◆ DeepEquals() [2/3]

bool PeanutButter.Utils.ObjectExtensions.DeepEquals ( this object objSource,
object objCompare,
ObjectComparisons comparison,
params string[] ignorePropertiesByName )
static

Runs a deep equality test between two objects, glossing over reference differences between class-types and comparing only primitive types. Use this when you'd like to essentially test whether the data in one object hierarchy matches that of another.

Parameters
objSourceObject which is the source of truth
objCompareObject to compare with
comparisonMethod for comparison
ignorePropertiesByNameParams array of properties to ignore by name
Returns

◆ DeepEquals() [3/3]

bool PeanutButter.Utils.ObjectExtensions.DeepEquals ( this object objSource,
object objCompare,
params string[] ignorePropertiesByName )
static

Runs a deep equality test between two objects, glossing over reference differences between class-types and comparing only primitive types. Use this when you'd like to essentially test whether the data in one object hierarchy matches that of another.

Parameters
objSourceObject which is the source of truth
objCompareObject to compare with
ignorePropertiesByNameParams array of properties to ignore by name
Returns

◆ DeepIntersectionEquals()

bool PeanutButter.Utils.ObjectExtensions.DeepIntersectionEquals ( this object objSource,
object objCompare,
params string[] ignorePropertiesByName )
static

Runs a deep equality test between two objects, using the properties common to both sides of the comparison to match on.

Parameters
objSourceSource object to perform comparison against
objCompareComparison object to compare
ignorePropertiesByNameOptional params array of properties to ignore by name
Returns
True if relevant properties are found and match; false otherwise. If no common properties are found, returns false; caveat: performing this comparison on two vanilla Object() instances will return true.

◆ DeepSubEquals()

bool PeanutButter.Utils.ObjectExtensions.DeepSubEquals ( this object objSource,
object objCompare,
params string[] ignorePropertiesByName )
static

Runs a deep equality test between two objects, using the properties on objSource (and children) as the set of properties to match on.

Parameters
objSourceSource object to perform comparison against
objCompareComparison object to compare
ignorePropertiesByNameOptional params array of properties to ignore by name
Returns
True if relevant properties are found and match; false otherwise

◆ DeserializeFromJson< T >()

T PeanutButter.Utils.ObjectExtensions.DeserializeFromJson< T > ( this string json)
static

Deserializes a json string to the type T, by first figuring out if T's properties are decorated for System.Text.Json or Newtonsoft.Json and then choosing the serializer accordingly.

Parameters
json
Template Parameters
T
Returns
Exceptions
NotImplementedException

◆ Get()

object PeanutButter.Utils.ObjectExtensions.Get ( this object src,
string propertyPath,
Type type )
static

Provides a non-generic interface to Get<T>.

Parameters
src
propertyPath
type
Returns

◆ Get< T >()

T PeanutButter.Utils.ObjectExtensions.Get< T > ( this object src,
string propertyPath )
static

Gets the value of a property on an object, specified by the property path, of the given Type.

Parameters
srcObject to search for the required property
propertyPathPath to the property: may be a property name or a dotted path down an object hierarchy, eg: Company.Name
Template Parameters
TExpected type of the property value
Returns

◆ GetOrDefault< T >() [1/2]

T PeanutButter.Utils.ObjectExtensions.GetOrDefault< T > ( this object src,
string propertyPath )
static

Gets the value of a property on an object, specified by the property path, of the given Type or returns a default value when that property cannot be found by path and/or type.

Parameters
src
propertyPath
Template Parameters
T
Returns

◆ GetOrDefault< T >() [2/2]

T PeanutButter.Utils.ObjectExtensions.GetOrDefault< T > ( this object src,
string propertyPath,
T defaultValue )
static

Gets the value of a property on an object, specified by the property path, of the given Type or returns a default value when that property cannot be found by path and/or type.

Parameters
src
propertyPath
defaultValue
Template Parameters
T
Returns

◆ GetPropertyValue()

object PeanutButter.Utils.ObjectExtensions.GetPropertyValue ( this object src,
string propertyPath )
static

Gets a property value by name from an object.

Parameters
srcSource object
propertyPathName of the property to search for
Returns
Value of the property, cast/boxed to object
Exceptions
MemberNotFoundExceptionThrown when the property is not found by name

◆ GetPropertyValue< T >()

T PeanutButter.Utils.ObjectExtensions.GetPropertyValue< T > ( this object src,
string propertyPath )
static

Gets an immediate property value, cast to the specified type.

Parameters
srcSource object
propertyPathImmediate property name
Template Parameters
TRequired type
Returns
Value of the property, if it can be found and cast. Will throw otherwise.

◆ HasProperty() [1/2]

bool PeanutButter.Utils.ObjectExtensions.HasProperty ( this object obj,
string prop )
static

Tests if the object has the requested property by path.

Parameters
obj
prop
Returns

◆ HasProperty() [2/2]

bool PeanutButter.Utils.ObjectExtensions.HasProperty ( this object obj,
string prop,
Type propertyType )
static

Tests if the object has the named property with the expected type.

Parameters
obj
prop
propertyType
Returns

◆ HasProperty< T >()

bool PeanutButter.Utils.ObjectExtensions.HasProperty< T > ( this object obj,
string prop )
static

Tests whether the object has the named property with the type T.

Parameters
obj
prop
Template Parameters
T
Returns

◆ InArray< T >()

T[] PeanutButter.Utils.ObjectExtensions.InArray< T > ( this T input)
static

Fluency extension to wrap a single item in an array, eg: new SomeBusinessObject().InArray().Union(SomeOtherCollection);.

Parameters
inputThe item to wrap
Template Parameters
TThe type of the object
Returns
A single-element array containing the input object

◆ InList< T >()

List< T > PeanutButter.Utils.ObjectExtensions.InList< T > ( this T input)
static

Fluency extension to wrap a single item in a list, eg: new SomeBusinessObject().InList().Union(SomeOtherCollection);.

Parameters
inputThe item to wrap
Template Parameters
TThe type of the object
Returns
A single-element list containing the input object

◆ InvokeMethodWithResult()

object PeanutButter.Utils.ObjectExtensions.InvokeMethodWithResult ( this object src,
string methodName,
params object[] args )
static

Invokes a method on an object, if available; otherwise explodes.

Parameters
srcObject to invoke the method on
methodNameMethod to invoke, by name
argsAny parameters to give to the method
Returns
return value of the method

◆ Is()

bool PeanutButter.Utils.ObjectExtensions.Is ( this object original,
object test )
static

Tests if two objects are the same reference in memory (ie, short-hand for object.ReferenceEquals(original, test);.

Parameters
original
test
Returns

◆ IsAssignableTo< T >()

bool PeanutButter.Utils.ObjectExtensions.IsAssignableTo< T > ( this Type type)
static

Tests if a type is assignable to another type (inverse of IsAssignableFrom)

Parameters
typeType to operate on
Template Parameters
TType to check assignment possibility against
Returns
True if objects of type {type} can be assigned to objects of type T

◆ IsInstanceOf()

bool PeanutButter.Utils.ObjectExtensions.IsInstanceOf ( this object obj,
Type type )
static

Tests if the given object is an instance of the provided type.

  • returns false if obj is null
  • returns true if the type is the exact type of obj
  • returns true if the type is a base type of obj
  • returns true if the type is an interface implemented by obj
  • returns false otherwise
Parameters
obj
type
Returns

◆ IsInstanceOf< T >()

bool PeanutButter.Utils.ObjectExtensions.IsInstanceOf< T > ( this object obj)
static

Tests if the given object is an instance of the type T.

  • returns false if obj is null
  • returns true if T is the exact type of obj
  • returns true if T is a base type of obj
  • returns true if T is an interface implemented by obj
  • returns false otherwise
Parameters
obj
Template Parameters
T
Returns

◆ IsRuntimeType()

bool PeanutButter.Utils.ObjectExtensions.IsRuntimeType ( this object obj)
static

Determines whether or not an arbitrary object is a RuntimeType.

Parameters
obj
Returns

◆ SerializeToJson< T >()

string PeanutButter.Utils.ObjectExtensions.SerializeToJson< T > ( this T item)
static

Serializes an object of type T to json, by first figuring out if T's properties are decorated for System.Text.Json or Newtonsoft.Json and then choosing the serializer accordingly.

Parameters
item
Template Parameters
T
Returns
Exceptions
NotImplementedException

◆ Set< T >()

void PeanutButter.Utils.ObjectExtensions.Set< T > ( this object src,
string propertyPath,
T newValue )
static

Attempts to set a property value on an object by property path.

Parameters
src
propertyPath
newValue
Template Parameters
T

◆ SetPropertyValue()

void PeanutButter.Utils.ObjectExtensions.SetPropertyValue ( this object src,
string propertyPath,
object newValue )
static

Attempts to set a property value on an object by property path.

Parameters
srcSource object to set property on
propertyPathPath into the property: could be an immediate property name or something like "Company.Name"
newValueNew value to attempt to set the property to
Exceptions
MemberNotFoundExceptionThrown when the property cannot be found

◆ ShapeEquals()

bool PeanutButter.Utils.ObjectExtensions.ShapeEquals ( this object objSource,
object objCompare,
params string[] ignorePropertiesByName )
static

Tests if two objects have the same "shape" – basically Deep Equality testing without actually testing final property values.

Parameters
objSourceSource / Master object
objCompareComparison object
ignorePropertiesByNameIgnore these properties by name
Returns
True if the "shapes" are the same, false otherwise

◆ ShapeSubEquals()

bool PeanutButter.Utils.ObjectExtensions.ShapeSubEquals ( this object objSource,
object objCompare,
params string[] ignorePropertiesByName )
static

Tests if a second object has at least the "shape" of a primary one. Basically a DeepSubEquals without testing final property values. without actually testing final property values.

Parameters
objSourceSource / Master object
objCompareComparison object
ignorePropertiesByNameIgnore these properties by name
Returns
True if the comparison object "contains the shape" of the source object, false otherwise

◆ ToFixed() [1/2]

decimal PeanutButter.Utils.ObjectExtensions.ToFixed ( this decimal value,
int places )
static

Provides a similar api to Javascript's .toFixed(), except returning a useful decimal! Note: this is different from .TruncateTo since that will truncate the value, whereas this will round.

Parameters
valueSource decimal value
placesNumber of decimal places required
Returns

◆ ToFixed() [2/2]

double PeanutButter.Utils.ObjectExtensions.ToFixed ( this double value,
int places )
static

Provides a similar api to Javascript's .toFixed(), except returning a useful double! Note: this is different from .TruncateTo since that will truncate the value, whereas this will round.

Parameters
valueSource double value
placesNumber of double places required
Returns

◆ TruncateTo() [1/2]

decimal PeanutButter.Utils.ObjectExtensions.TruncateTo ( this decimal value,
int places )
static

Truncates a decimal value to a required number of places.

Parameters
valueSource decimal value
placesNumber of decimal places required
Returns
A new decimal value which is the original value truncated to the required places

◆ TruncateTo() [2/2]

double PeanutButter.Utils.ObjectExtensions.TruncateTo ( this double value,
int places )
static

Truncates a decimal value to a required number of places.

Parameters
valueSource decimal value
placesNumber of decimal places required
Returns
A new decimal value which is the original value truncated to the required places

◆ TryChangeType()

bool PeanutButter.Utils.ObjectExtensions.TryChangeType ( this object input,
Type requiredType,
out object output )
static

Analogous to TryParse methods, this will attempt to convert a value to the type requiredType, returning true if it can, and populating the output parameter.

Parameters
inputValue to work on
requiredTypeThe required type
outputOutput parameter to collect result
Returns
True when can ChangeType, false otherwise

◆ TryChangeType< T >()

bool PeanutButter.Utils.ObjectExtensions.TryChangeType< T > ( this object input,
out T output )
static

Analogous to TryParse methods, this will attempt to convert a value to the type T, returning true if it can, and populating the output parameter.

Parameters
inputValue to work on
outputOutput parameter to collect result
Template Parameters
TDesired type
Returns
True when can ChangeType, false otherwise

◆ TryGet< T >()

bool PeanutButter.Utils.ObjectExtensions.TryGet< T > ( this object obj,
string propertyPath,
out T result )
static

Attempt to retrieve the named property with the given type off of the provided object.

Parameters
obj
propertyPath
result
Template Parameters
T
Returns

◆ TrySet< T >()

bool PeanutButter.Utils.ObjectExtensions.TrySet< T > ( this object src,
string propertyPath,
T newValue )
static

attempts to set a property value on an object by path and value

  • will not throw on error, but will return false instead
Parameters
src
propertyPath
newValue
Template Parameters
T
Returns

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/ObjectExtensions.cs