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.Runtime.CompilerServices; | |
// where が多いほど優先度を上げておかないと ambiguous エラー起こす。 | |
// where の数が同じものは優先度も同じで大丈夫。 | |
Console.WriteLine("* A"); | |
A.M<C1, C1>(); | |
A.M<C2, C1>(); | |
A.M<C1, C2>(); | |
A.M<C2, C2>(); |
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.Runtime.CompilerServices; | |
Ex.M<C1>(); // where class | |
Ex.M<S1>(); // where struct | |
Ex.M<C2>(); // where class, I | |
Ex.M<S2>(); // where struct, I | |
Ex.M<I>(); // これは class, I に行く。インターフェイスは参照型なので。 | |
static void M1<T>() => Ex.M<T>(); // none |
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.Buffers; | |
using System.Diagnostics; | |
using System.Runtime.CompilerServices; | |
/// <summary> | |
/// とりあえず Add する一方の Dictionary 的な実装。 | |
/// ちゃんと「増えすぎたら古いのから消す」みたいな処理入れるなら自前でやるのちょっとつらく、 | |
/// Ben.StringIntern とかの導入考えた方がよさげ。 | |
/// </summary> | |
class InternPool |
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.Text.Json.Serialization; | |
using System.Text.Json.Serialization.Metadata; | |
IJsonTypeInfoResolver r = new SourceGenerationContext(); | |
Console.WriteLine(r.GetTypeInfo(typeof((One, TwoThree)), new()) is null); // not null | |
Console.WriteLine(r.GetTypeInfo(typeof((OneTwo, Three)), new()) is null); // null | |
// タプルのとき、 source generator が作るメソッドの名前は Create_Value{T1}{T2} らしく… | |
[JsonSourceGenerationOptions(WriteIndented = true)] |
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.Runtime.CompilerServices; | |
#if false | |
M(new A { X = 1 }); | |
M(new B { X = 1 }); | |
M(new A { Y = 2 }); | |
M(new B { Y = 2 }); | |
M(new A { X = 1, Y = 2 }); | |
M(new B { X = 1, Y = 2 }); | |
M(new A { }); |
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.Runtime.CompilerServices; | |
int x = 1; | |
_ = x.M(); // 拡張メソッドの this 引数は ref 渡しできる。 | |
_ = (x * x).M(); // ref 渡しには右辺値は渡せないので M(ref int) を呼べない。 | |
// M(int) の方呼んでほしいけどもダメっぽい。エラーに。 | |
static class A | |
{ |
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.Runtime.CompilerServices; | |
using static Enumerable; | |
int[][] x = [[]]; | |
var y = x.Sum(x => x.Sum(x => 1)); | |
#if false | |
// Same as System.Linq.Enumerable, this causes CS9236. | |
static class Enumerable |
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 BenchmarkDotNet.Attributes; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
using C = System.Globalization.CultureInfo; | |
#if DEBUG | |
var data = ToHexStringBenchmark.StaticData; | |
var s = data.A1(); | |
Console.WriteLine(data.A1() == s); |
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
namespace ConsoleApp1 | |
{ | |
using System.Runtime.CompilerServices; | |
file class Gen | |
{ | |
[InterceptsLocation(@"F:\src\ConsoleApp1\ConsoleApp1\Program.cs", 1, 16)] | |
public static ReadOnlySpan<byte> M1(string _) => [1, 2, 3, 10, 11, 12, 100, 200, 255]; | |
[InterceptsLocation(@"F:\src\ConsoleApp1\ConsoleApp1\Program.cs", 2, 16)] | |
public static ReadOnlySpan<byte> M2(string _) => [0x83, 0x01, 0x01, 0x02, 0xC3, 0x61, 0x62, 0x63, 0x03, 0xA2, 0xFF, 0x00]; |
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
// (int)Math.Floor(float.MaxValue) は、 | |
// .NET 8 だとなぜか int.MinValue | |
// .NET 9 だと int.MaxValue になってそう。 | |
// .NET 9 でだけ永久ループ… | |
M((int)Math.Floor(float.MaxValue), (int)Math.Floor(float.MaxValue)); | |
Console.WriteLine("done."); | |
static void M(int x, int y) |
NewerOlder