Skip to content

Instantly share code, notes, and snippets.

View meziantou's full-sized avatar

Gérald Barré meziantou

View GitHub Profile
<HttpRequestLoggerComponent />
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
@meziantou
meziantou / DumpSourceFilesFromPortablePdb.cs
Last active September 23, 2022 08:34
Dump source files from a portable pdb
// Convert full pdb to portable pdb: https://github.com/dotnet/symreader-converter#pdb2pdb
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Reflection.Metadata;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
@meziantou
meziantou / benchmark.cs
Created February 11, 2020 01:42
Struct - HashSet benchmark
public class Hashset
{
[Benchmark]
public void HashSet_Int32()
{
var hashset = new HashSet<int>();
for (int i = 0; i < 1000; i++)
{
hashset.Add(i);
}
@meziantou
meziantou / Range.cs
Last active December 28, 2020 16:42
C# 8: Index and Range
// https://www.meziantou.net/how-to-use-csharp-8-indices-and-ranges-in-dotnet-standard-2-0-and-dotn.htm
#pragma warning disable MA0048 // File name must match type name
#define INTERNAL_NULLABLE_ATTRIBUTES
#if NETSTANDARD2_0 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48
// https://github.com/dotnet/corefx/blob/48363ac826ccf66fbe31a5dcb1dc2aab9a7dd768/src/Common/src/CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@meziantou
meziantou / program.cs
Created March 31, 2019 18:20
Collection performance
internal static class Program
{
private static void Main()
{
BenchmarkRunner.Run<Remove>();
}
}
[CoreJob]
[MemoryDiagnoser]
[Benchmark]
public string V1()
{
return string.Create(13, _id, (buffer, id) =>
{
var encode32CharsArray = _encode32CharsArray;
buffer[0] = encode32CharsArray[(id >> 60) & 31];
buffer[1] = encode32CharsArray[(id >> 55) & 31];
buffer[2] = encode32CharsArray[(id >> 50) & 31];
.NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT
BranchmarkString.Benchmark.V6()
return string.Create(13, _id, (buffer, id) =>
^^^
{
^^^
var encode32CharsArray = _encode32CharsArray;
^^^
buffer[12] = encode32CharsArray[id & 31];
^^^
@meziantou
meziantou / program.cs
Created December 10, 2018 02:23
XSLT sample
static void Main(string[] args)
{
var xsl = XDocument.Parse(@"<xsl:stylesheet version=""1.0""
xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""
xmlns:msxsl=""urn:schemas-microsoft-com:xslt""
xmlns:user=""http://dummy/ns"">
<msxsl:script language=""C#"" implements-prefix=""user"">
<![CDATA[
public string Code()
{