Skip to content

Instantly share code, notes, and snippets.

public static class IncrementalGeneratorInitializationContextExtensions
{
public static IncrementalValuesProvider<T> ForAttributeWithMetadataNameWithOptions<T>(
this IncrementalGeneratorInitializationContext context,
string fullyQualifiedMetadataName,
Func<SyntaxNode, CancellationToken, bool> predicate,
Func<GeneratorAttributeSyntaxContext, AnalyzerConfigOptions, CancellationToken, T> transform)
{
var syntaxContext = context.SyntaxProvider.ForAttributeWithMetadataName(
fullyQualifiedMetadataName,
using Microsoft.Extensions.DependencyInjection;
public sealed class KeyedServiceProxy<T>
where T : notnull
{
private readonly IServiceProvider serviceProvider;
public KeyedServiceProxy(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
@usausa
usausa / Program.cs
Last active February 4, 2024 09:33
Command line server
Directory.SetCurrentDirectory(AppContext.BaseDirectory);
var host = Host.CreateDefaultBuilder(args)
.UseWindowsService()
.UseSystemd()
.ConfigureLogging(config =>
{
config.ClearProviders();
})
.ConfigureServices((context, services) =>
@usausa
usausa / CallBenchmark.cs
Last active December 22, 2023 12:23
CallBenchmark
namespace CallBenchmark;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
@usausa
usausa / TcpServer.cs
Created October 1, 2023 12:04
TCP server using Microsoft.AspNetCore.Connections
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseKestrel(options =>
{
options.ListenLocalhost(9999, config =>
{
config.UseConnectionHandler<MyConnectionHandler>();
});
});
var app = builder.Build();
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
public static class HexEncoder
{
private static ReadOnlySpan<byte> HexTable => new[]
{
(byte)'0', (byte)'1', (byte)'2', (byte)'3',
(byte)'4', (byte)'5', (byte)'6', (byte)'7',
(byte)'8', (byte)'9', (byte)'A', (byte)'B',
(byte)'C', (byte)'D', (byte)'E', (byte)'F'
};

interface

7FF81390136B mov       rcx,[rsi+8]
7FF81390136F mov       r11,7FF8135903A8
7FF813901379 call      qword ptr [7FF8135903A8]

abstract

@usausa
usausa / Program.cs
Last active November 1, 2022 09:59
Microsoft.Data.Sqlite Mutlithread test
using System.CommandLine;
using System.CommandLine.NamingConventionBinder;
using System.Diagnostics;
using Microsoft.Data.Sqlite;
using Smart.Data.Mapper;
#pragma warning disable CA1812
@usausa
usausa / SlidingPager.cs
Created September 4, 2022 05:21
SlidingPager
public sealed class SlidingPager<T> : IList<T>
{
private readonly List<T> source;
private readonly Func<T, DateTime> selector;
private int end;
private int start;