Skip to content

Instantly share code, notes, and snippets.

View in-async's full-sized avatar

inasync in-async

View GitHub Profile
@in-async
in-async / UriTemplate1.cs
Last active February 16, 2022 12:53
URI Template Level 1
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Commons {
public class UriTemplate1 {
public static void Expand(TextWriter writer, string template, IDictionary<string, object?> parameters) {
@in-async
in-async / Optional.cs
Last active January 25, 2022 13:49
Optional<T> 型
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
namespace Inasync {
//[TypeDescriptionProvider(typeof(OptionalTypeDescriptionProvider))]
[TypeConverter(typeof(OptionalTypeConverter))]
@in-async
in-async / AutoImpl.csproj
Last active January 20, 2022 10:14
インターフェース(のプロパティ)を自動実装する Source Generator (仮)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
<ItemGroup>
@in-async
in-async / FieldTracking.csproj
Created January 20, 2022 06:58
SourceGenerator を利用して、エンティティのダーティ値を取得するコードを自動生成する案
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
<ItemGroup>
@in-async
in-async / ExpressionFunc.cs
Last active January 14, 2022 08:48
式ブロック的なヘルパー。
using System;
namespace Commons {
/// <remarks>
/// cf. Proposal: Expression blocks https://github.com/dotnet/csharplang/issues/3086
/// cf. Proposal: Sequence Expressions https://github.com/dotnet/csharplang/issues/377
/// </remarks>
public static class ExpressionFunc {
@in-async
in-async / EnumerableExtensions.cs
Created December 7, 2021 11:31
IEnumerable<T> の列挙が完了したら指定したオブジェクトを自動的に Dispose
using System;
using System.Collections.Generic;
namespace Commons {
public static class EnumerableExtensions {
public static IEnumerable<T> WithDisposable<T>(this IEnumerable<T> source, IDisposable disposable) {
try {
foreach (T item in source) {
@in-async
in-async / Prorate.cs
Last active September 10, 2021 07:53
汎用按分器 in .NET
/// Usage
void Main() {
var weights = new decimal[] { 4, 6, 7.3m };
Prorate(total: 1014, weights: weights, ProrationRounding.SpecifiedOrder).Dump(nameof(ProrationRounding.SpecifiedOrder));
Prorate(total: 1014, weights: weights, ProrationRounding.DecimalPartDescending).Dump(nameof(ProrationRounding.DecimalPartDescending));
ProrateExact(total: 1014, weights: weights).Dump(nameof(ProrateExact));
}
/// <summary>
@in-async
in-async / StringSplitExtensions.cs
Created July 23, 2021 04:23
predicate による文字列分割を行う `String` 拡張メソッド。
#nullable enable
using System;
using System.Collections.Generic;
namespace Commons {
public delegate bool StringSplitPredicate(ref int index);
public static class StringExtensions {
@in-async
in-async / NaturalSortComparer.cs
Last active July 23, 2021 04:55
自然順ソート (Natural sort order) を行う `IComparer<T>` の実装。
#nullable enable
using System;
using System.Collections.Generic;
namespace Commons {
/// <summary>
/// 自然順ソート (Natural sort order) を行う <see cref="IComparer{T}"/> の実装。
/// cf. https://ja.wikipedia.org/wiki/%E8%87%AA%E7%84%B6%E9%A0%86
@in-async
in-async / EnumerableComparer.cs
Last active July 23, 2021 04:21
シーケンスの比較を行う `IComparer<T>` 実装。
#nullable enable
using System;
using System.Collections.Generic;
namespace Commons {
/// <summary>
/// シーケンスの比較を行う <see cref="IComparer{T}"/> 実装。
/// </summary>