This file contains hidden or 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; | |
| using System.IO; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| /// <summary> | |
| /// Thread-safe stream wrapper that discards certain operations on the underlying stream as a lifetime control measure.<br/> | |
| /// If intention is only to read, external code should only read from the stream, other unintended operations will be discarded.<br/> | |
| /// In case external code tries to manage lifetime of the stream, on <see cref="Stream.Dispose()"/> the underlying stream isn't being disposed. | |
| /// </summary> |
This file contains hidden or 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 class MethodSignatureComparer : IEqualityComparer<ParameterInfo> | |
| { | |
| public static readonly MethodSignatureComparer Default = new(); | |
| public bool Match(MethodInfo signatureMethod, MethodInfo otherMethod) | |
| { | |
| var signatureParameters = signatureMethod.GetParameters(); | |
| var parameters = otherMethod.GetParameters(); | |
| if (otherMethod.Name != signatureMethod.Name) |
This file contains hidden or 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; | |
| using System.Runtime.CompilerServices; | |
| // our code | |
| MyType obj = new(); | |
| MyExtension ext = (MyExtension)obj; | |
| ext.MyField = 42; | |
| // other code | |
| ext = (MyExtension)obj; |
This file contains hidden or 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 SequenceEqualityComparer<T> : IEqualityComparer<IEnumerable<T>> | |
| { | |
| public readonly IEqualityComparer<T> Comparer; | |
| public SequenceEqualityComparer(IEqualityComparer<T>? comparer = null) | |
| { | |
| Comparer = comparer ?? EqualityComparer<T>.Default; | |
| } | |
| public static readonly SequenceEqualityComparer<T> Instance = new(); |
This file contains hidden or 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
| function inprint(table) | |
| print(table) | |
| for key, value in pairs(table) do | |
| print('\t['..key..'] = ['..value..']') | |
| end | |
| end |
This file contains hidden or 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 string? CapitalizeFirstLetter(this string? text) | |
| { | |
| if (string.IsNullOrWhiteSpace(text)) return text; | |
| StringBuilder result = new(text); | |
| var length = text!.Length; | |
| for (var i = 0; i < length; i++) | |
| { | |
| var c = text[i]; |
This file contains hidden or 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; | |
| using System.Globalization; | |
| public enum Language : int | |
| { | |
| Arabic = 1, | |
| German = 7, | |
| English = 9, | |
| Spanish = 10, | |
| French = 12, |
This file contains hidden or 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; | |
| using System.Linq; | |
| using System.Collections.Generic; | |
| /// <summary> | |
| /// Enum extensions. | |
| /// </summary> | |
| public static class EnumExtensions | |
| { | |
| /// <inheritdoc cref="EnumExtensions{TEnum}.Values"/> |
This file contains hidden or 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 class ConditionalWeakDictionary<TKey, TValue> : IDictionary<TKey, TValue> | |
| where TKey : class | |
| where TValue : class | |
| { | |
| private readonly ConditionalWeakTable<TKey, TValue> table = new(); | |
| public TValue this[TKey key] | |
| { | |
| get => Get(key); | |
| set => Set(key, value); |
This file contains hidden or 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
| /// <summary> | |
| /// <see cref="List{T}"/> with functionality of <see cref="Queue{T}"/> that allows to enqueue elements in order using <see cref="Comparison{T}"/>. | |
| /// </summary> | |
| /// <typeparam name="T">Type of elements.</typeparam> | |
| public class OrderedQueue<T> : List<T> | |
| { | |
| public OrderedQueue(Comparison<T> comparison = null) | |
| { | |
| OrderComparison = comparison ?? ((a, b) => a.Equals(b) ? 0 : -1); | |
| } |
NewerOlder