All C# extension methods for type object
-
Dump
Dumps the object as a json string. Can be used for logging object contents.
-
ToJson() and FromJson<T>()
Convert an object to JSON an back
-
IsNull
check value is null
-
Clone<T>()
Makes a copy from the object.
-
IfNotNull<T, TResult>
if the object this method is called on is not null, runs the given function and returns the value. if the object is null, returns default(TResult).
-
Simplify usage of XmlSerializer
Extension for simplify usage of XmlSerializer class. Add extension to any object serialize it to xml. Add extension to string and stream to deserialize objects. All extensions with first check about default constructor
-
ToXML
Serializes an object to XML
-
Equals
Equals method that lets you specify on what property or field value you want to compare an object on. Also compares the object types. Useful to use in an overridden Equals method of an object.
-
IfNotNull
Returns a selected value when the source is not null; null otherwise.
-
SerializeToXml
Serializes objects to an xml string. (Does not provide error handling if the object is not serializable.)
-
ChangeType
Converts any type to another.
-
IsNull
Unified advanced generic check for: DbNull.Value, INullable.IsNull, !Nullable<>.HasValue, null reference. Omits boxing for value types.
-
TryDispose
Dispose an object if it implement IDisposable. Especially useful when working with interfaces and object factories, and IDisposable may or may not found on concrete class.
-
Return<TIn, TOut>
A 'fluent' logic extension method that takes a value (can be anything) and a function that returns another value (can be anything) based on its logic. This is useful for both evaluating and optionally returning a value without declaring a temporary variable for the value.
-
IsDefault
Returns true if the object it is called upon is the default of its type. This will be null for referece types, zero for integer types, and a default-initialized struct for structs.
-
ToNull
Turns any object to null
-
NotEmpty
Determines if the object is null or empty. string is evaluated with empty. Collections, Arrays and Dictionaries are evaluated for 0 items (items themselves may be null) All other objects are evaluated as null or not null.
-
Extend
An extenssion function to work like the extend method of javascript. It takes the object and merge with oder, but only if the property of the other object has value.
-
GetValue
Gets the value of a databinded property-path from an object. The property can have the form "Product.Type.Group".
-
IsNullOrDBNull
We all know that objects can be null, but when dealing with databases, a new null type shows up, the DBNull. This extention method detects it along with the null.
-
ToDelimitedString<T>(char delimiter, Func<T, PropertyInfo, string> func)
Map any object T to a delimited string and control how that string is formatted.
-
Pipe
It is like pipe operator in F# and is useful for chaining function calls especially in expressions. (More in http://foop.codeplex.com/)
-
Like SQL on C#
An C# extension method based on "LIKE" operator of T-SQL.
-
If
Executes a function if a given predicate is true
-
ToNull
Turns any object to null
-
ThrowIf
Throw's a given exception is a given predicate is True
-
Object properties to dictionary converter
Takes all public properties of any object and inserts then into a dictionary
-
Identity
Returns the identity of a value
-
SpinThread
Spins up and executes the action within a thread. Basically fire and forget. Real big question here. Does anybody see any issues with thread management? I would like to update this with any code necessary to manage thread cleanup if necessary. I realize that this has the ability to create unsafe thread referencing if not written such that the contents of the action are exclusive to the scope of the action, but that is outside the purview of this extension
-
In
Allows you to compare a value to a list of values analogous to the 'In' statement in sql. This makes for a very friendly syntax that is (IMHO) superior to a list of 'or' clauses. Instead of : if (s=="John" || s=="Peter" or s=="Paul") one can write if (s.In("John","Paul","Peter"))
-
IfType
Execute code only on certain types
-
Is
simple fluent assert for MSTest
-
ToString(NullOptions)
This ToString() version is null aware. That means it has different behaviors if the object's value is null or DBNull according to the NullOptions enum.
-
Accept
Provides a generic visitor Method Extension for more information, please have a look at my blog post : http://www.dotnetguru2.org/nicolaspenin/index.php?title=generic_visitor_implementation_thanks_to_0&more=1&c=1&tb=1&pb=1
-
IsNull
A better IsNull() implementation. Returns true if object value is null or DBNull
-
IfIs<T>
optionally executes an Action if the object is of the given type.
-
ThrowIfDefault
Throws a given Exception if the given object is equal to the default value for the type
-
IsDefaultForType
Returns true or false depending on if the given object is equal to the default(T) value of the type.
-
In
Determines whether a IEnumerable<T> contains a specific value
-
ToSortedString
Returns an alphabetically sorted list for all public and instance properties, along with its associated values.
-
ImplementsInterfaces(List<Type> types)
Determines if a class object implements an interface type and returns a list of types it actually implements. If no matching type is found an empty list will be returned.
-
In
Checks if object is any of provided values separated by comma
-
Quick writeline
Write a variable to System.Diagnostics.Debug.WriteLine() (Or other output method)
-
IsMatch
Matches yourFace to myButt
-
WriteToXML
Serializes objects into and from XML documents
-
Convert a Rectangular to a Jagged Array
Converts a T[,] (rectangular array) to a T[][] (jagged array).
-
Shorthand ReferenceEquals
This extension method represents shorthand version of ReferenceEquals method.