This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DataThread | |
{ | |
public static Action<DataTable> UpdateDelegate { get; set; } | |
public static void Execute(TimeSpan updateRate, TimeSpan sleepRate) | |
{ | |
var key = int.MinValue; | |
var dataTable = CreateDataTable(); | |
var columns = dataTable.Columns; | |
var rows = dataTable.Rows; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static CancellationToken Timeout(this CancellationToken cancellationToken, TimeSpan timeout) | |
{ | |
if (!cancellationToken.CanBeCanceled) | |
return new CancellationTokenSource(timeout).Token; | |
var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); | |
cancellationTokenSource.CancelAfter(timeout); | |
return cancellationTokenSource.Token; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Flush(ConsoleLogger consoleLogger) | |
{ | |
var fieldInfo = typeof(ConsoleLogger).GetField("_queueProcessor", BindingFlags.Instance | BindingFlags.NonPublic); | |
var consoleLoggerProcessor = (ConsoleLoggerProcessor)fieldInfo.GetValue(consoleLogger); | |
consoleLoggerProcessor.Dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal sealed class ReadOnlySequenceConsumer | |
{ | |
readonly List<string> _result = new List<string>(); | |
public IReadOnlyList<string> Result => _result; | |
public void Consume(ReadOnlySequence<byte> message) => _result.Add(GetString(message)); | |
public string GetString(ReadOnlySequence<byte> message) => message.IsSingleSegment ? Encoding.ASCII.GetString(message.First.Span) : string.Create((int)message.Length, message, GetChars); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISerializer | |
{ | |
bool TryDeserialize<T>([CanBeNull] byte[] value, [CanBeNull] out T result) where T : class; | |
bool TrySerialize<T>([CanBeNull] T value, [NotNull] out byte[] result, bool compress = false) where T : class; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"new byte[] {" + string.Join(", ", File.ReadAllBytes(@"C:\filename")) + "};" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DictionaryExtensions | |
{ | |
public static string ToXUnitAssertion<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> dictionary, string variableName = "dictionary") | |
{ | |
var isKeyString = typeof(TKey) == typeof(string); | |
var isValueString = typeof(TValue) == typeof(string); | |
string GetKey(TKey key) => isKeyString ? $"\"{key}\"" : key.ToString(); | |
string GetValue(TValue value) => isValueString ? $"\"{value}\"" : value.ToString(); | |
var stringBuilder = new StringBuilder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[PublicAPI] | |
public static partial class DictionaryExtensions | |
{ | |
/// <summary> | |
/// Adds a key/value pair to the <see cref="T:System.Collections.Generic.IDictionary`2" /> by using the specified | |
/// function, if the key does not already exist. | |
/// </summary> | |
/// <param name="dictionary">the dictionary to get or add from</param> | |
/// <param name="key">The key of the element to add.</param> | |
/// <param name="valueFactory">The function used to generate a value for the key</param> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class ObservableExtensions | |
{ | |
public static IObservable<TResponse> IgnoreElements<TSource, TResponse>(this IObservable<TSource> sequence) => new IgnoreElementsObservable<TSource, TResponse>(sequence); | |
sealed class IgnoreElementsObservable<TSource, TResult> : IObservable<TResult> | |
{ | |
readonly IObservable<TSource> _sequence; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class JsonLogger : IDisposable | |
{ | |
readonly string _fileName; | |
readonly JsonSerializer _jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings | |
{ | |
NullValueHandling = NullValueHandling.Ignore, | |
Formatting = Formatting.None, | |
Converters = new JsonConverter[] {new StringEnumConverter()} | |
}); |