Class Extensions
OptimaJet.Workflow.Core.Extensions
Provides extension methods used by core workflow engine components.
Namespace: OptimaJet.Workflow.Core
public static class ExtensionsMethods
public static XElement SingleOrDefault(this XElement element, string name) #Gets the current XElement when its name matches; otherwise, gets the only direct child with the requested name.
Parameters
Name
Type
Description
elementXElementThe source XML element.
nameStringThe XML name to match.
Returns
Type
Description
XElementThe current element when its name equals
name, the only matching direct child element with that name, or null when none is found.Exceptions
Type
Description
InvalidOperationExceptionMore than one direct child has the requested name.
public static Type ToNullableType(this Type type) #Gets a nullable equivalent for value types.
Parameters
Name
Type
Description
typeTypeThe source type.
Returns
Type
Description
TypeThe corresponding Nullable<T> type for a value type, the original nullable type when
type is already nullable, or the original type for a reference type.public static bool IsNullable(this Type type) #Determines whether a type is a nullable value type.
Parameters
Name
Type
Description
typeTypeThe type to inspect.
Returns
Type
Description
Booleanpublic static Type GetUnderlyingType(this Type type) #Gets the non-nullable underlying type for a nullable type.
Parameters
Name
Type
Description
typeTypeThe type to inspect.
Returns
Type
Description
TypeThe underlying type argument for Nullable<T> values, or the original type when the value is not nullable.
public static object GetDefaultValue(this Type type) #Gets the default value for a type.
Parameters
Name
Type
Description
typeTypeThe type whose default value to create.
Returns
Type
Description
ObjectThe zero-initialized value for value types, or null for reference types.
public static bool IsNumeric(this Type type) #Determines whether the type is one of the numeric types recognized by the engine.
public static string ToLowerCaseString(this bool value) #Returns the bool value as lower-case text.
Parameters
Name
Type
Description
valueBooleanThe value to convert.
Returns
Type
Description
Stringtrue as true and false as false.public static bool ExtendedEquals(this object value, object valueToCompare) #Compares two values with an extended rule for enumerable types.
Parameters
Name
Type
Description
valueObjectThe value to compare.
valueToCompareObjectThe value to compare against.
Returns
Remarks
When both values are non-null, have the same runtime type, and implement IEnumerable, comparison is performed element-by-element by index.
public static string ToFormattedString<T>(this List<T> value, bool quotate) #Converts a list into a delimited string, using a comma as the separator.
Parameters
Name
Type
Description
valueList<T>The list to serialize.
quotateBooleanWhether each item should be wrapped in single quotes.
Returns
Type
Description
StringThe formatted string representation.
public static string ToFormattedString<T>(this List<T> value, string delimeter, bool quotate) #Converts a list into a delimited string.
Parameters
Name
Type
Description
valueList<T>The list to serialize.
delimeterStringThe delimiter to place between list items.
quotateBooleanWhether each item should be wrapped in single quotes.
Returns
Type
Description
StringThe formatted string representation.
public static bool TryGetValueIgnoreCase<TV>(this IDictionary<string, TV> dictionary, string key, out TV value) #Tries to get a value from a dictionary using a case-insensitive key match.
Parameters
Name
Type
Description
dictionaryIDictionary<String, TV>The dictionary to query.
keyStringThe key to match in a case-insensitive manner.
Returns
public static dynamic ToDynamic(this Dictionary<string, object> dictionary) #Creates a dynamic object from a string/object dictionary.
Parameters
Name
Type
Description
dictionaryDictionary<String, Object>The source dictionary.
Returns
Type
Description
dynamicAn ExpandoObject containing all dictionary entries.
public static string ToValidCSharpIdentifierName(this string originalString) #Converts non-empty text to an identifier-compatible string by replacing unsupported characters and adding a leading underscore when required.
Parameters
Name
Type
Description
originalStringStringThe non-null, non-empty source text.
Returns
Type
Description
StringA sanitized identifier-compatible string. C# keywords are not escaped.
Exceptions
Type
Description
ArgumentNullExceptionoriginalString is null.ArgumentOutOfRangeExceptionoriginalString is empty.public static T? FirstOrNull<T>(this IEnumerable<T> items, Func<T, bool> predicate) where T : struct #Returns the first element that matches a predicate, or null when no elements match.
Parameters
Name
Type
Description
itemsIEnumerable<T>The sequence to search.
predicateFunc<T, Boolean>The predicate used to test each element.
Returns
Type
Description
Nullable<T>A nullable
T value for the first matching element, or null.Exceptions
Type
Description
ArgumentNullExceptionpublic static bool IsSimpleDynamicType(this Type type) #Determines whether a type is considered a simple type for dynamic bindings.
public static T CastAs<T>(this object obj) #Casts an object to the requested type when the runtime type is assignable.
Parameters
Name
Type
Description
objObjectThe source object.
Returns
Type
Description
{T}The object cast to
T when valid, otherwise the default value of T.public static bool TryCast<T>(this object obj, out T newValue) #Tries to cast an object to a requested type.