Class Extensions
Defines Extensions.
Inherited Members
Namespace: Microsoft.Graph.Communications.Common
Assembly: Microsoft.Graph.Communications.Common.dll
Syntax
public static class Extensions
Methods
ChangeType(Object, Type)
Returns an object of the specified type and whose value is equivalent to the specified object.
Declaration
public static object ChangeType(this object value, Type conversionType)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | value | An object that implements the IConvertible interface. |
| Type | conversionType | The type of object to return. |
Returns
| Type | Description |
|---|---|
| Object | Converted object |
Exceptions
| Type | Condition |
|---|---|
| InvalidCastException | This conversion is not supported. -or- |
| FormatException |
|
| OverflowException |
|
| ArgumentNullException |
|
ChangeType<T>(Object)
Convert conversionType of an object
Declaration
public static T ChangeType<T>(this object value)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | value | An object that implements the IConvertible interface. |
Returns
| Type | Description |
|---|---|
| T | Converted object |
Type Parameters
| Name | Description |
|---|---|
| T | Type requested |
Exceptions
| Type | Condition |
|---|---|
| InvalidCastException | This conversion is not supported. -or- |
| FormatException |
|
| OverflowException |
|
| ArgumentNullException |
CreateObserver<T>(IObservable<T>, Action<T>, Action<Exception>, Action)
Create observer
Declaration
public static Observer<T> CreateObserver<T>(this IObservable<T> observable, Action<T> onNext, Action<Exception> onError = null, Action onCompleted = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IObservable<T> | observable | Object providing the events. |
| Action<T> | onNext | Callback for data. |
| Action<Exception> | onError | Callback for errors. |
| Action | onCompleted | Callback for completion. |
Returns
| Type | Description |
|---|---|
| Observer<T> | New observer object |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the observer. |
GetDeterministicHashCode(String)
Gets deterministic hash code of the given string. Using FNV-1a hash: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
Declaration
public static uint GetDeterministicHashCode(this string str)
Parameters
| Type | Name | Description |
|---|---|---|
| String | str | The string. |
Returns
| Type | Description |
|---|---|
| UInt32 | The unsigned hash code. |
Lock(Mutex)
Lock mutex
Declaration
public static IDisposable Lock(this Mutex mutex)
Parameters
| Type | Name | Description |
|---|---|---|
| Mutex | mutex | Mutex to enter. |
Returns
| Type | Description |
|---|---|
| IDisposable | Disposable cleanup to release mutex. |
Pin(Object)
Pin object memory.
Declaration
public static AutoClean<IntPtr> Pin(this object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | Object to pin. |
Returns
| Type | Description |
|---|---|
| AutoClean<IntPtr> | Disposable cleanup to release pinned memory. |
PushDir(String)
Push directory and restore when done.
Declaration
public static IDisposable PushDir(string directory)
Parameters
| Type | Name | Description |
|---|---|---|
| String | directory | New directory to change to. |
Returns
| Type | Description |
|---|---|
| IDisposable | Disposable to restore to previous directory. |
Read(ReaderWriterLockSlim)
Automatic cleanup of entering read lock.
Declaration
public static IDisposable Read(this ReaderWriterLockSlim lockSlim)
Parameters
| Type | Name | Description |
|---|---|---|
| ReaderWriterLockSlim | lockSlim | Lock instance. |
Returns
| Type | Description |
|---|---|
| IDisposable | Disposable cleanup instance. |
ReplaceFirst(String, String, String)
Replaces the first occurence of search string with replace string.
Declaration
public static string ReplaceFirst(this string text, string search, string replace)
Parameters
| Type | Name | Description |
|---|---|---|
| String | text | The source text. |
| String | search | The search string. |
| String | replace | String to be replaced. |
Returns
| Type | Description |
|---|---|
| String | Updated soruce text. |
ReplaceScheme(Uri, String, String)
Replace URI scheme.
Declaration
public static Uri ReplaceScheme(this Uri uri, string find, string replace)
Parameters
| Type | Name | Description |
|---|---|---|
| Uri | uri | Subject URI |
| String | find | Find string. |
| String | replace | Replace string. |
Returns
| Type | Description |
|---|---|
| Uri | New URI. |
SafeWait(SemaphoreSlim)
Safe wait on semaphore
Declaration
public static IDisposable SafeWait(this SemaphoreSlim semaphoreSlim)
Parameters
| Type | Name | Description |
|---|---|---|
| SemaphoreSlim | semaphoreSlim | The semaphore to wait on. |
Returns
| Type | Description |
|---|---|
| IDisposable | Disposable cleanup to release semaphore. |
SafeWaitAsync(SemaphoreSlim)
Safe wait on semaphore
Declaration
public static Task<IDisposable> SafeWaitAsync(this SemaphoreSlim semaphoreSlim)
Parameters
| Type | Name | Description |
|---|---|---|
| SemaphoreSlim | semaphoreSlim | The semaphore to wait on. |
Returns
| Type | Description |
|---|---|
| Task<IDisposable> | Disposable cleanup to release semaphore. |
TrapErrors(Action, IGraphLogger, TraceLevel, String, String, String, Int32)
Trap exceptions from action.
Declaration
public static Exception TrapErrors(this Action action, IGraphLogger logger, TraceLevel level, string component = "", string memberName = null, string filePath = null, int lineNumber = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | action | Action to run. |
| IGraphLogger | logger | Logger to log exception data. |
| TraceLevel | level | Trace level. |
| String | component | The component in which this log is created. |
| String | memberName | Calling function. |
| String | filePath | Filename where code is located. |
| Int32 | lineNumber | Line number where code is located. |
Returns
| Type | Description |
|---|---|
| Exception | Task containing exception if any. |
TrapErrors<TKey>(Action<TKey>, TKey, IGraphLogger, TraceLevel, String, String, String, Int32)
Trap exceptions from action.
Declaration
public static Exception TrapErrors<TKey>(this Action<TKey> action, TKey key, IGraphLogger logger, TraceLevel level, string component = "", string memberName = null, string filePath = null, int lineNumber = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<TKey> | action | Action to run. |
| TKey | key | Key for the action. |
| IGraphLogger | logger | Logger to log exception data. |
| TraceLevel | level | Trace level. |
| String | component | The component in which this log is created. |
| String | memberName | Calling function. |
| String | filePath | Filename where code is located. |
| Int32 | lineNumber | Line number where code is located. |
Returns
| Type | Description |
|---|---|
| Exception | Task containing exception if any. |
Type Parameters
| Name | Description |
|---|---|
| TKey | Action key type. |
TrapErrorsAsync(Task, IGraphLogger, TraceLevel, String, String, String, Int32)
Trap exceptions from antecedent task.
Declaration
public static Task<Exception> TrapErrorsAsync(this Task task, IGraphLogger logger, TraceLevel level, string component = "", string memberName = null, string filePath = null, int lineNumber = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | Antecedent task. |
| IGraphLogger | logger | Logger to log exception data. |
| TraceLevel | level | Trace level. |
| String | component | The component in which this log is created. |
| String | memberName | Calling function. |
| String | filePath | Filename where code is located. |
| Int32 | lineNumber | Line number where code is located. |
Returns
| Type | Description |
|---|---|
| Task<Exception> | Task containing exception if any. |
TryDispose(Object, IGraphLogger)
Try and dispose the object if it supports the right interface.
Declaration
public static void TryDispose(this object obj, IGraphLogger logger = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | Object to dispose. |
| IGraphLogger | logger | Logger instance. |
UpgradeableRead(ReaderWriterLockSlim)
Automatic cleanup of entering read lock.
Declaration
public static IDisposable UpgradeableRead(this ReaderWriterLockSlim lockSlim)
Parameters
| Type | Name | Description |
|---|---|---|
| ReaderWriterLockSlim | lockSlim | Lock instance. |
Returns
| Type | Description |
|---|---|
| IDisposable | Disposable cleanup instance. |
WaitAsync(Task, Int32)
Waits for the Task to complete execution within a specified number of milliseconds. Traps errors on the task to avoid unobserved task exceptions.
Declaration
public static Task<bool> WaitAsync(this Task task, int millisecondsTimeout = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | Task to wait. |
| Int32 | millisecondsTimeout | The number of milliseconds to wait, or Infinite (-1) to wait indefinitely. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if the Task completed execution within the allotted time; otherwise, false. |
Write(ReaderWriterLockSlim)
Automatic cleanup of entering write lock.
Declaration
public static IDisposable Write(this ReaderWriterLockSlim lockSlim)
Parameters
| Type | Name | Description |
|---|---|---|
| ReaderWriterLockSlim | lockSlim | Lock instance. |
Returns
| Type | Description |
|---|---|
| IDisposable | Disposable cleanup instance. |