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 CustomJsonSerializerOptions | |
{ | |
public static readonly JsonSerializerOptions Options = new() { | |
PropertyNamingPolicy = new SnakeCaseJsonNamingPolicy(), | |
PropertyNameCaseInsensitive = true, | |
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | |
Converters = { | |
new JsonStringEnumConverter (new SnakeCaseJsonNamingPolicy()), | |
// Other converters | |
} |
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 TaskEx | |
{ | |
public static async Task<(T1, T2)> WhenAll<T1, T2>(Task<T1> task1, Task<T2> task2) | |
{ | |
await Task.WhenAll(task1, task2); | |
return (task1.GetAwaiter().GetResult(), task2.GetAwaiter().GetResult()); | |
} | |
public static async Task<(T1, T2, T3)> WhenAll<T1, T2, T3>(Task<T1> task1, Task<T2> task2, Task<T3> task3) | |
{ |
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 WithTimeoutExtension | |
{ | |
public static Task WithTimeout(this Task task, int timeout, string actionName = null) => task.WithTimeout(TimeSpan.FromMilliseconds(timeout), actionName); | |
public static async Task WithTimeout(this Task task, TimeSpan timeout, string actionName = null) | |
{ | |
var delay = Task.Delay(timeout); | |
var completedTask = await Task.WhenAny(task, delay); | |
if (completedTask == task) | |
{ |
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; | |
namespace DataAccess | |
{ | |
public static class TypeExtensions | |
{ | |
public static Type? SearchType(this Type type, Type searchType) | |
{ | |
return searchType.IsInterface | |
? SearchInterfaceType(type, searchType) |
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
import logging | |
__author__ = 'WerWolf' | |
def trace(logger, level=logging.INFO): | |
def wrapped(func): | |
def tmp(*args, **kwargs): | |
if logger.isEnabledFor(level): | |
logger.log(level, "Start %s" % func.__name__) |
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 EnumConverter<TEnum> | |
where TEnum : Enum | |
{ | |
private static readonly Dictionary<int, TEnum> _values; | |
static EnumConverter() | |
{ | |
_values = new Dictionary<int, TEnum>(); | |
var enumValues = Enum.GetValues(typeof(TEnum)); |
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 CustomDbContext : DbContext | |
{ | |
// ... | |
protected override void OnConfiguring(DbContextOptionsBuilder options) | |
{ | |
// Replace default materializer source to custom, to convert DateTimes | |
options.ReplaceService<IEntityMaterializerSource, DateTimeKindEntityMaterializerSource>(); | |
base.OnConfiguring(options); |
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
/******************************************************* | |
* | |
* Created by: Alexander Puzynia aka WerWolf | |
* Created: 17.10.2010 23:36 | |
* | |
* File: MemberAccessorHelper.cs | |
* Remarks: | |
* | |
* History: | |
* 17.10.2010 23:36 - Create Wireframe |
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 AccessPrivateWrapper : DynamicObject | |
{ | |
/// <summary> | |
/// The object we are going to wrap | |
/// </summary> | |
private readonly object _instance; | |
/// <summary> | |
/// Specify the flags for accessing members | |
/// </summary> |
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 StaticReflection | |
{ | |
public static MemberExpression GetMemberExpression(LambdaExpression expression) | |
{ | |
return GetMemberExpression() ?? throw new ArgumentException(@"Not a member access", nameof(expression)); | |
MemberExpression GetMemberExpression() | |
{ | |
switch (expression.Body.NodeType) | |
{ |
NewerOlder