Skip to content

Instantly share code, notes, and snippets.

View Spoiler.cs
// compile with C# 8
class C
{
void M()
{
// in C# 8 you'll get a warning here but neither T? nor [AllowNull] will be allowed
void M<T>(T t = default) { } // CS8601
}
}
@TessenR
TessenR / Code.cs
Last active Dec 21, 2020
Generator adding logging to locks
View Code.cs
using System;
using System.Threading;
using System.Threading.Tasks;
using DeadlockDemo;
using JetBrains.Annotations;
var test = new MyDeadlockDemoWithLogging();
Console.WriteLine("Running without deadlock...");
test.MyFirstMethod(false);
@TessenR
TessenR / LinksDescription.md
Last active Nov 22, 2021
Source generators in action links
View LinksDescription.md
@TessenR
TessenR / ChainedGenerators.cs
Last active Aug 26, 2020
Chained source generators where subsequent generators aware of the previous generators' changes
View ChainedGenerators.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using Microsoft.CodeAnalysis;
@TessenR
TessenR / Generator.cs
Created Aug 26, 2020
Iterative source generator reusing types from previous iterations
View Generator.cs
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
[Generator]
public class Generator : ISourceGenerator
View MagicBool
using System;
using System.Runtime.InteropServices;
static class Program
{
static void Main(string[] args)
{
bool b = GetTricksyBool();
if (b) Console.WriteLine(b.IsTrue());
}