Skip to content

Instantly share code, notes, and snippets.

public class MyClass
{
public static LargeStruct StaticMethod(MyClass obj)
{
// ...
}
public LargeStruct InstanceMethod()
{
// ...
public struct SomeStruct
{
public int Value1;
}
public unsafe class Getter
{
private delegate*<Obj, SomeStruct> _functionPointer;
public Getter(string propName)
{
var methodInfo = typeof(Obj).GetProperty(propName).GetGetMethod();
_functionPointer = (delegate*<Obj, SomeStruct>)methodInfo.MethodHandle.GetFunctionPointer();
}
using System;
using System.Runtime.InteropServices;
namespace ManagedDotnetProfiler;
public class DllMain
{
[UnmanagedCallersOnly(EntryPoint = "DllGetClassObject")]
public static unsafe int DllGetClassObject(Guid* rclsid, Guid* riid, IntPtr* ppv)
{
@kevingosse
kevingosse / Program.cs
Created March 26, 2022 15:18
Extract native code from dynamic method
using Microsoft.Diagnostics.Runtime;
using System;
using System.Linq;
namespace ExtractDynamicMethod
{
internal class Program
{
static void Main(string[] args)
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.Diagnostics.Runtime;
namespace ClrmdAsyncLocal
{
internal class Program
{
[MemoryDiagnoser]
public class EmptyEnumerator
{
[Benchmark(Baseline = true)] public bool ArrayEmpty() => Array.Empty<string>().GetEnumerator().MoveNext();
[Benchmark] public bool ArrayEmptyAsEnumerable() => ((IEnumerable<string>)Array.Empty<string>()).GetEnumerator().MoveNext();
[Benchmark] public bool ArrayEmptyForEach()
{
foreach (var _ in Array.Empty<string>())
[AsyncMethodBuilder(typeof(UiTaskMethodBuilder))]
public class UiTask
{
internal TaskCompletionSource<object> Promise { get; } = new TaskCompletionSource<object>();
public Task AsTask() => Promise.Task;
public TaskAwaiter<object> GetAwaiter()
{
return Promise.Task.GetAwaiter();
using System;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace ThreadTasks
{
class Program
{
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
namespace IsEvenSourceGenerator
{
[Generator]