-
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Common C# Extensions for Developers
-
CommonExtensions
- DeHumanize(humanized,delimiter)
- Distinct``2(this,keySelector)
- Extend``1(target,source)
- ForAwait(task)
- ForAwait(task)
- ForAwait``1(task)
- ForAwait``1(task)
- Format(value,arg0)
- Format(value,args)
- GetDefault(type)
- Humanize(value)
- IfIs``1(target,method)
- IfIs``2(target,method)
- IfNotNull``2(source,selector)
- In(value,stringValues)
- In``1(source,list)
- IsDecimal(input)
- IsDouble(input)
- IsInt(input)
- IsNotNull(input)
- IsNull``1(me)
- IsNull``1(me)
- IsSet(input)
- Left(value,length)
- Like(value,search)
- ReferenceEquals(objA,objB)
- Return``2(value,evaluateFunc)
- Right(value,length)
- SpinThread``1(parms,action)
- SplitCamelCase(source)
- ThrowIf``1(val,predicate,exceptionFunc)
- ToDecimal(input)
- ToDouble(input)
- ToEnum``1(value)
- ToInt(input)
- ToLogString(ex,additionalMessage)
- ToNull(_)
- ToUrlSlug(value)
System
Defines the CommonExtensions
Make Readable string Dirty
The String
Name | Type | Description |
---|---|---|
humanized | System.String | humanized stringString |
delimiter | System.String | delimiter String |
Provides a Distinct method that takes a key selector lambda as parameter. The .net framework only provides a Distinct method that takes an instance of an implementation of IEqualityComparer where the standard parameter less Distinct that uses the default equality comparer doesn't suffice.
Name | Type | Description |
---|---|---|
this | System.Collections.Generic.IEnumerable{``0} | IEnumerable. |
keySelector | System.Func{``0,``1} | key selector. |
Name | Description |
---|---|
T | |
TKey | The type of the key. |
An extension 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.
Name | Type | Description |
---|---|---|
target | ``0 | The target |
source | ``0 | The source |
Name | Description |
---|---|
T |
The ForAwait
The ConfiguredValueTaskAwaitable
Name | Type | Description |
---|---|---|
task | System.Threading.Tasks.ValueTask@ | The taskValueTask |
The ForAwait
Name | Type | Description |
---|---|---|
task | System.Threading.Tasks.Task | The taskTask |
The ForAwait
The ConfiguredValueTaskAwaitable`1
Name | Type | Description |
---|---|---|
task | System.Threading.Tasks.ValueTask{``0}@ | The taskValueTask`1 |
Name | Description |
---|---|
T |
The ForAwait
Name | Type | Description |
---|---|---|
task | System.Threading.Tasks.Task{``0} | The taskTask`1 |
Name | Description |
---|---|
T |
Replaces the format item in a specified System.String with the text equivalent of the value of a specified System.Object instance.
The String
Name | Type | Description |
---|---|---|
value | System.String | A composite format string |
arg0 | System.Object | An System.Object to format |
Replaces the format item in a specified System.String with the text equivalent of the value of a specified System.Object instance.
The String
Name | Type | Description |
---|---|---|
value | System.String | A composite format string |
args | System.Object[] | An System.Object array containing zero or more objects to format. |
The GetDefault
The Object
Name | Type | Description |
---|---|---|
type | System.Type | The typeType |
Human Readable string
The String
Name | Type | Description |
---|---|---|
value | System.String | The valueString |
allows an action to be taken on an object if it is castable as the given type, with no return value. if the target does not match the type, does nothing
Name | Type | Description |
---|---|---|
target | System.Object | The targetObject |
method | System.Action{``0} | The methodAction`1 |
Name | Description |
---|---|
T |
allows an action to be taken on an object if it is castable as the given type, with a return value. if the target does not match the type, returns default(T)
Name | Type | Description |
---|---|---|
target | System.Object | The targetObject |
method | System.Func{``0,``1} | The methodFunc`2 |
Name | Description |
---|---|
T | |
TResult |
Returns a selected value when the source is not null; null otherwise.
The selected value when source is not null; null otherwise.
Name | Type | Description |
---|---|---|
source | ``0 | The source |
selector | System.Func{``0,``1} | The selectorFunc`2 |
Name | Description |
---|---|
T | |
TInner |
Checks string object's value to array of string values
Return true if any string value matches
Name | Type | Description |
---|---|---|
value | System.String | The valueString |
stringValues | System.String[] | Array of string values to compare |
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"))
The Boolean
Name | Type | Description |
---|---|---|
source | ``0 | The source |
list | ``0[] | The list |
Name | Description |
---|---|
T |
Check string IsDecimal
The Boolean
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Check string IsDouble
The Boolean
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Check string IsInt
The Boolean
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Check if Input string is not null or whitespace
The Boolean
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Check IsNull
The Boolean
Name | Type | Description |
---|---|---|
me | ``0 | The me |
Name | Description |
---|---|
T |
Check IsNull
True or False Boolean
Name | Type | Description |
---|---|---|
me | System.Nullable{``0} | Struct need to check is null |
Name | Description |
---|---|
T | Where T is struct |
Check if string is null or empty
True or False Boolean
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Returns characters from left of specified length
Returns string from left
Name | Type | Description |
---|---|---|
value | System.String | String value |
length | System.Int32 | Max number of characters to return |
An C# extension method based on "LIKE" operator of T-SQL.
The Boolean
Name | Type | Description |
---|---|---|
value | System.String | The valueString |
search | System.String | The searchString |
This extension method represents shorthand version of ReferenceEquals method.
The Boolean
Name | Type | Description |
---|---|---|
objA | System.Object | The objAObject |
objB | System.Object | The objBObject |
Returns a value based on an provided value and evaluation function
Name | Type | Description |
---|---|---|
value | ``0 | The value |
evaluateFunc | System.Func{``0,``1} | The evaluateFuncFunc`2 |
Name | Description |
---|---|
TIn | |
TOut |
Returns characters from right of specified length
Returns string from right
Name | Type | Description |
---|---|---|
value | System.String | String value |
length | System.Int32 | Max number of charaters to return |
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
Name | Type | Description |
---|---|---|
parms | ``0 | The parms |
action | System.Action{``0} | The actionAction`1 |
Name | Description |
---|---|
T |
Split Camel Case string to space delimited
spited string array
Name | Type | Description |
---|---|---|
source | System.String | The sourceString |
Throw's a given exception is a given predicate is True
Name | Type | Description |
---|---|---|
val | ``0 | The val |
predicate | System.Func{``0,System.Boolean} | The predicate[](#!-Func<T, bool> 'Func<T, bool>') |
exceptionFunc | System.Func{System.Exception} | The exceptionFuncFunc`1 |
Name | Description |
---|---|
T |
Converts string to ToDecimal
The Decimal
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Converts string to ToDouble
The Double
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Converts string to enum object
Returns enum object
Name | Type | Description |
---|---|---|
value | System.String | String value to convert |
Name | Description |
---|---|
T | Type of enum |
The ToInt
The Int32
Name | Type | Description |
---|---|---|
input | System.String | The inputString |
Creates a log-string from the Exception.
The result includes the stacktrace, innerexception et cetera, separated by .
Name | Type | Description |
---|---|---|
ex | System.Exception | The exception to create the string from. |
additionalMessage | System.String | Additional message to place at the top of the string, maybe be empty or null. |
Make object Null
The Object
Name | Type | Description |
---|---|---|
_ | System.Object | _Object |
Make Url Slug
The String
Name | Type | Description |
---|---|---|
value | System.String | The valueString |