Class Extensions
Extension methods.
Inherited Members
Namespace: Swan
Syntax
public static class Extensions
Methods
CopyKeyValuePairTo(IDictionary<String, Object>, Object, String[])
Iterates over the keys of the source and tries to write a compatible value to a public, instance, writable property in the destination.
Declaration
public static int CopyKeyValuePairTo(this IDictionary<string, object> source, object target, params string[] ignoreKeys)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<String, Object> | source | The source. |
| Object | target | The target. |
| String[] | ignoreKeys | The ignore keys. |
Returns
| Type | Description |
|---|---|
| Int32 | Number of properties that was copied successful. |
CopyKeyValuePairToNew<T>(IDictionary<String, Object>, String[])
Iterates over the keys of the source and tries to write a compatible value to a public, instance, writable property in the destination.
Declaration
public static T CopyKeyValuePairToNew<T>(this IDictionary<string, object> source, params string[] ignoreKeys)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<String, Object> | source | The source. |
| String[] | ignoreKeys | The ignore keys. |
Returns
| Type | Description |
|---|---|
| T | The specified type with properties copied. |
Type Parameters
| Name | Description |
|---|---|
| T | Object Type. |
CopyOnlyPropertiesTo(Object, Object, String[])
Iterates over the public, instance, readable properties of the source and tries to write a compatible value to a public, instance, writable property in the destination.
Declaration
public static int CopyOnlyPropertiesTo(this object source, object target, params string[] propertiesToCopy)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | source | The source. |
| Object | target | The destination. |
| String[] | propertiesToCopy | Properties to copy. |
Returns
| Type | Description |
|---|---|
| Int32 | Number of properties that were successfully copied. |
CopyOnlyPropertiesToNew<T>(Object, String[])
Copies the only properties to new instance of T.
Declaration
public static T CopyOnlyPropertiesToNew<T>(this object source, params string[] propertiesToCopy)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| Object | source | The source. |
| String[] | propertiesToCopy | The properties to copy. |
Returns
| Type | Description |
|---|---|
| T | The specified type with properties copied. |
Type Parameters
| Name | Description |
|---|---|
| T | Object Type. |
CopyPropertiesTo<T>(T, Object, String[])
Iterates over the public, instance, readable properties of the source and tries to write a compatible value to a public, instance, writable property in the destination.
Declaration
public static int CopyPropertiesTo<T>(this T source, object target, params string[] ignoreProperties)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | source | The source. |
| Object | target | The target. |
| String[] | ignoreProperties | The ignore properties. |
Returns
| Type | Description |
|---|---|
| Int32 | Number of properties that was copied successful. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the source. |
CopyPropertiesToNew<T>(Object, String[])
Copies the properties to new instance of T.
Declaration
public static T CopyPropertiesToNew<T>(this object source, string[] ignoreProperties = null)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| Object | source | The source. |
| String[] | ignoreProperties | The ignore properties. |
Returns
| Type | Description |
|---|---|
| T | The specified type with properties copied. |
Type Parameters
| Name | Description |
|---|---|
| T | The new object type. |
ForEach<TKey, TValue>(IDictionary<TKey, TValue>, Action<TKey, TValue>)
Executes the item action for each element in the Dictionary.
Declaration
public static void ForEach<TKey, TValue>(this IDictionary<TKey, TValue> dict, Action<TKey, TValue> itemAction)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<TKey, TValue> | dict | The dictionary. |
| Action<TKey, TValue> | itemAction | The item action. |
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of the key. |
| TValue | The type of the value. |
GetCopyableProperties(Object)
Gets the copyable properties.
If there is no properties with the attribute AttributeCache returns all the properties.
Declaration
public static IEnumerable<string> GetCopyableProperties(this object this)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | this | The object. |
Returns
| Type | Description |
|---|---|
| IEnumerable<String> | Array of properties. |
GetOrAdd<TKey, TValue>(IDictionary<TKey, TValue>, TKey, Func<TKey, TValue>)
Adds a key/value pair to the Dictionary if the key does not already exist.
If the value is null, the key will not be updated.
Based on ConcurrentDictionary.GetOrAdd method.
Declaration
public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, Func<TKey, TValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<TKey, TValue> | dict | The dictionary. |
| TKey | key | The key. |
| Func<TKey, TValue> | valueFactory | The value factory. |
Returns
| Type | Description |
|---|---|
| TValue | The value for the key. |
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of the key. |
| TValue | The type of the value. |
GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)
Gets the value if exists or default.
Declaration
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultValue = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<TKey, TValue> | dict | The dictionary. |
| TKey | key | The key. |
| TValue | defaultValue | The default value. |
Returns
| Type | Description |
|---|---|
| TValue | The value of the provided key or default. |
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of the key. |
| TValue | The type of the value. |
Retry(Action, TimeSpan, Int32)
Does the specified action.
Declaration
public static void Retry(this Action action, TimeSpan retryInterval = null, int retryCount = 3)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | action | The action. |
| TimeSpan | retryInterval | The retry interval. |
| Int32 | retryCount | The retry count. |
Retry<T>(Func<T>, TimeSpan, Int32)
Does the specified action.
Declaration
public static T Retry<T>(this Func<T> action, TimeSpan retryInterval = null, int retryCount = 3)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T> | action | The action. |
| TimeSpan | retryInterval | The retry interval. |
| Int32 | retryCount | The retry count. |
Returns
| Type | Description |
|---|---|
| T | The return value of the method that this delegate encapsulates. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the source. |