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; | |
using System.Runtime.CompilerServices; | |
// our code | |
MyType obj = new(); | |
MyExtension ext = (MyExtension)obj; | |
ext.MyField = 42; | |
// other code | |
ext = (MyExtension)obj; |
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 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 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 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 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 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 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 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); | |
} |
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
/// <summary> | |
/// Creates new <see cref="LinkedList{T}"/> with reversed nodes. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
public static LinkedList<T> Reverse<T>(this LinkedList<T> originalList) | |
{ | |
var reversedList = new LinkedList<T>(); | |
var last = originalList.Last; | |
reversedList.AddFirst(last.Value); | |
while ((last = last.Previous) is not null) |
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; | |
using System.Threading.Tasks; | |
public static class TaskExtensions | |
{ | |
public delegate void ExceptionCallback(Exception exception); | |
public delegate void CompleteCallback<in T>(T result); | |
public delegate void CompleteCallback(); | |
public static Task<T> WithResult<T>(this Task task, Func<Task, T> func) => |
NewerOlder