Class Utility
Utility methods.
Inheritance
Inherited Members
Namespace: FM.LiveSwitch
Assembly: FM.LiveSwitch.dll
Syntax
public class Utility
Methods
Clone<T>(List<T>)
Clones the specified list.
Declaration
public static List<T> Clone<T>(List<T> list)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<T> | list | The list. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<T> |
Type Parameters
Name | Description |
---|---|
T |
CloneIntArray(Int32[])
Clones an array of int values.
Declaration
public static int[] CloneIntArray(int[] intArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | intArray | An array of int values. |
Returns
Type | Description |
---|---|
System.Int32[] |
CloneLongArray(Int64[])
Clones an array of long values.
Declaration
public static long[] CloneLongArray(long[] longArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int64[] | longArray | An array of long values. |
Returns
Type | Description |
---|---|
System.Int64[] |
CloneStringArray(String[])
Clones an array of string values.
Declaration
public static string[] CloneStringArray(string[] stringArray)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | stringArray | An array of string values. |
Returns
Type | Description |
---|---|
System.String[] |
FirstOrDefault<T>(T[])
Gets the first element in the array or the default value if the array is null or empty.
Declaration
public static T FirstOrDefault<T>(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
FirstOrDefault<T>(List<T>)
Gets the first element in the list or the default value if the list is null or empty.
Declaration
public static T FirstOrDefault<T>(List<T> list)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<T> | list | The list. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
FormatDoubleAsPercent(Double, Int32)
Formats a double as a percentage string.
Declaration
public static string FormatDoubleAsPercent(double value, int decimalPlaces)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The value. |
System.Int32 | decimalPlaces | The number of decimal places to include. |
Returns
Type | Description |
---|---|
System.String |
GenerateId()
Generates a globally unique identifier with no hyphens.
Declaration
public static string GenerateId()
Returns
Type | Description |
---|---|
System.String | A globally unique identifier with no hyphens. |
GenerateSynchronizationSource()
Generates a synchronization source.
Declaration
public static long GenerateSynchronizationSource()
Returns
Type | Description |
---|---|
System.Int64 |
GenerateTieBreaker()
Generates a tie-breaker.
Declaration
[Obsolete("Use GenerateId instead.")]
public static string GenerateTieBreaker()
Returns
Type | Description |
---|---|
System.String | A tie-breaker. |
GetRtpSequenceNumberDelta(Int32, Int32)
Retrieves the difference between two RTP sequence numbers while accounting for overflow rollover.
Declaration
public static int GetRtpSequenceNumberDelta(int rtpSequenceNumber, int lastRtpSequenceNumber)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rtpSequenceNumber | The current RTP sequence number. |
System.Int32 | lastRtpSequenceNumber | The last (previous) RTP sequence number. |
Returns
Type | Description |
---|---|
System.Int32 | The difference between the two RTP sequence numbers. |
GetRtpTimestampDelta(Int64, Int64)
Retrieves the difference between two RTP timestamps while accounting for overflow rollover.
Declaration
public static long GetRtpTimestampDelta(long rtpTimestamp, long lastRtpTimestamp)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | rtpTimestamp | The current RTP timestamp. |
System.Int64 | lastRtpTimestamp | The last (previous) RTP timestamp. |
Returns
Type | Description |
---|---|
System.Int64 | The difference between the two RTP timestamps. |
LastOrDefault<T>(T[])
Gets the last element in the array or the default value if the array is null or empty.
Declaration
public static T LastOrDefault<T>(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
LastOrDefault<T>(List<T>)
Gets the last element in the list or the default value if the list is null or empty.
Declaration
public static T LastOrDefault<T>(List<T> list)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<T> | list | The list. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
NullableLongEquals(Nullable<Int64>, Nullable<Int64>)
Compares two nullable longs for equality.
Declaration
public static bool NullableLongEquals(long? long1, long? long2)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int64> | long1 | The first long value. |
System.Nullable<System.Int64> | long2 | The second long value. |
Returns
Type | Description |
---|---|
System.Boolean |
SingleOrDefault<T>(T[])
Gets the only element in the array or the default value if the array is null or does not have exactly one value.
Declaration
public static T SingleOrDefault<T>(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
SingleOrDefault<T>(List<T>)
Gets the only element in the list or the default value if the list is null or does not have exactly one value.
Declaration
public static T SingleOrDefault<T>(List<T> list)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<T> | list | The list. |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Splice<T>(T[], Int32, T[], Function1<Int32, T[]>)
Splices an array.
Declaration
public static T[] Splice<T>(T[] array, int index, T[] addItems, Function1<int, T[]> createArray)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array. |
System.Int32 | index | The splice index. |
T[] | addItems | The items to add. |
Function1<System.Int32, T[]> | createArray | A function that creates an array of the given size. |
Returns
Type | Description |
---|---|
T[] |
Type Parameters
Name | Description |
---|---|
T | The array element type. |
Splice<T>(T[], Int32, Int32, T[], Function1<Int32, T[]>)
Splices an array.
Declaration
public static T[] Splice<T>(T[] array, int index, int removeCount, T[] addItems, Function1<int, T[]> createArray)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array. |
System.Int32 | index | The splice index. |
System.Int32 | removeCount | The number of items to remove. |
T[] | addItems | The items to add. |
Function1<System.Int32, T[]> | createArray | A function that creates an array of the given size. |
Returns
Type | Description |
---|---|
T[] |
Type Parameters
Name | Description |
---|---|
T | The array element type. |
Splice<T>(T[], Int32, Int32, Function1<Int32, T[]>)
Splices an array.
Declaration
public static T[] Splice<T>(T[] array, int index, int removeCount, Function1<int, T[]> createArray)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array. |
System.Int32 | index | The splice index. |
System.Int32 | removeCount | The number of items to remove. |
Function1<System.Int32, T[]> | createArray | A function that creates an array of the given size. |
Returns
Type | Description |
---|---|
T[] |
Type Parameters
Name | Description |
---|---|
T | The array element type. |
ToIntArray(List<Int32>)
Converts a list of int values to an array of int values.
Declaration
public static int[] ToIntArray(List<int> intList)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.Int32> | intList | A list of int values. |
Returns
Type | Description |
---|---|
System.Int32[] |
ToList<T>(T[])
Converts an array to a list.
Declaration
public static List<T> ToList<T>(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The array. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<T> |
Type Parameters
Name | Description |
---|---|
T |
ToLongArray(List<Int64>)
Converts a list of long values to an array of long values.
Declaration
public static long[] ToLongArray(List<long> longList)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.Int64> | longList | A list of long values. |
Returns
Type | Description |
---|---|
System.Int64[] |
ToStringArray(List<String>)
Converts a list of string values to an array of string values.
Declaration
public static string[] ToStringArray(List<string> stringList)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.String> | stringList | A list of string values. |
Returns
Type | Description |
---|---|
System.String[] |
TreeFindLeaves<T>(T, Function1<T, T[]>, Action1<T>)
Enumerates over all nodes in the tree, invoking the callback for each one.
Declaration
public static void TreeFindLeaves<T>(T root, Function1<T, T[]> childrenCallback, Action1<T> nodeCallback)
Parameters
Type | Name | Description |
---|---|---|
T | root | The root. |
Function1<T, T[]> | childrenCallback | The children callback. |
Action1<T> | nodeCallback | The node callback. |
Type Parameters
Name | Description |
---|---|
T | The generic to search. |
TreeSearch<T>(T, Function1<T, T[]>, Action1<T>)
Enumerates over all nodes in the tree, invoking the callback for each one.
Declaration
public static void TreeSearch<T>(T root, Function1<T, T[]> childrenCallback, Action1<T> nodeCallback)
Parameters
Type | Name | Description |
---|---|---|
T | root | The root. |
Function1<T, T[]> | childrenCallback | The children callback. |
Action1<T> | nodeCallback | The node callback. |
Type Parameters
Name | Description |
---|---|
T | The generic to search. |