Assembly: OptimaJet.Workflow.Core

Class Extensions

OptimaJet.Workflow.Core.Extensions

Provides extension methods used by core workflow engine components.

public static class Extensions

Methods

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
element
XElement
The source XML element.
name
String
The XML name to match.

Returns

Type
Description
XElement
The 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
InvalidOperationException
More 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
type
Type
The source type.

Returns

Type
Description
Type
The 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
type
Type
The type to inspect.

Returns

Type
Description
Boolean
true when type is constructed from Nullable<T>; otherwise false.
public static Type GetUnderlyingType(this Type type) #
Gets the non-nullable underlying type for a nullable type.

Parameters

Name
Type
Description
type
Type
The type to inspect.

Returns

Type
Description
Type
The 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
type
Type
The type whose default value to create.

Returns

Type
Description
Object
The 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.

Parameters

Name
Type
Description
type
Type
The type to check.

Returns

Type
Description
Boolean
true when type is exactly one of the supported numeric types; otherwise false.
public static string ToLowerCaseString(this bool value) #
Returns the bool value as lower-case text.

Parameters

Name
Type
Description
value
Boolean
The value to convert.

Returns

Type
Description
String
true 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
value
Object
The value to compare.
valueToCompare
Object
The value to compare against.

Returns

Type
Description
Boolean
true when the values are equal by this method's comparison rules; otherwise false.

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
value
List<T>
The list to serialize.
quotate
Boolean
Whether each item should be wrapped in single quotes.

Returns

Type
Description
String
The 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
value
List<T>
The list to serialize.
delimeter
String
The delimiter to place between list items.
quotate
Boolean
Whether each item should be wrapped in single quotes.

Returns

Type
Description
String
The 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
dictionary
IDictionary<String, TV>
The dictionary to query.
key
String
The key to match in a case-insensitive manner.
value
{TV}
When the method returns true, contains the matching value; otherwise the default value.

Returns

Type
Description
Boolean
true when exactly one key matches key ignoring case; otherwise false.
public static dynamic ToDynamic(this Dictionary<string, object> dictionary) #
Creates a dynamic object from a string/object dictionary.

Parameters

Name
Type
Description
dictionary
Dictionary<String, Object>
The source dictionary.

Returns

Type
Description
dynamic
An 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
originalString
String
The non-null, non-empty source text.

Returns

Type
Description
String
A sanitized identifier-compatible string. C# keywords are not escaped.

Exceptions

Type
Description
ArgumentNullException
originalString is null.
ArgumentOutOfRangeException
originalString 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
items
IEnumerable<T>
The sequence to search.
predicate
Func<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
ArgumentNullException
Thrown when items or predicate is null.
public static bool IsSimpleDynamicType(this Type type) #
Determines whether a type is considered a simple type for dynamic bindings.

Parameters

Name
Type
Description
type
Type
The type to inspect.

Returns

Type
Description
Boolean
true when the type is a primitive type or one of the supported additional simple types; otherwise false.
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
obj
Object
The 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.

Parameters

Name
Type
Description
obj
Object
The source object.
newValue
{T}
When the method returns true, the casted value; otherwise default.

Returns

Type
Description
Boolean
true when the cast succeeds; otherwise false.