Skip to content

Instantly share code, notes, and snippets.

Avatar
😵
On other projects, not checking GitHub notifications - ping via Teams if urgent.

Levi Broderick GrabYourPitchforks

😵
On other projects, not checking GitHub notifications - ping via Teams if urgent.
View GitHub Profile
@GrabYourPitchforks
GrabYourPitchforks / ref-asm.cs
Last active May 27, 2022
Type name parsing
View ref-asm.cs
public sealed class PublicKeyToken : IEquatable<PublicKeyToken>
{
public PublicKeyToken(byte[] publicKeyTokenBytes);
public PublicKeyToken(ReadOnlySpan<byte> publicKeyTokenBytes);
public PublicKeyToken(string publicKeyTokenHexString);
public PublicKeyToken(ReadOnlySpan<char> publicKeyTokenHexString);
public ReadOnlySpan<byte> RawBytes { get; }
public string TokenString { get; }
public byte[] GetPublicKeyTokenBytes();
View oob_rune.md

Problem summary

While working on the System.Text.Encodings.Web refactoring I noticed that we have several duplicates of the System.Text.Rune type (or its backing logic) throughout our projects.

The official implementation exposed by System.Runtime:

A copy used by the Utf8String OOB:

@GrabYourPitchforks
GrabYourPitchforks / fnptrs_reflection.md
Last active Jan 29, 2021
Draft function pointers in reflection spec
View fnptrs_reflection.md

Draft function pointers in reflection spec

Passing function pointers as parameters to MethodInfo.Invoke

The reflection stack should treat function pointer arguments as standard pointer arguments for the purposes of method invocation. This means that boxed IntPtr arguments should be accepted as parameters to these methods in MethodInfo.Invoke scenarios. For methods which return function pointers, they should be returned as boxed IntPtrs.

The reflection stack, for convenience, should also consider allowing developers to pass System.Reflection.Pointer instances as input arguments to these methods.

Inspecting function pointer types

@GrabYourPitchforks
GrabYourPitchforks / csharp_singlecopy_struct.md
Last active Mar 31, 2021
C# single-copy struct proposal
View csharp_singlecopy_struct.md

Problem statement and core scenario

We want to introduce the idea of a value type where the underlying data is only ever "live" in at most one place. The canonical example is the internal ValueStringBuilder struct type, which performs internal ArrayPool management.

ValueStringBuilder builder = new ValueStringBuilder(); // VSB is a struct type
builder.Append("foo");
builder.Append(obj);
HelperMethod(ref builder); // builder passed by ref to helper methods
return builder.ToString(); // ToString releases underlying rented arrays back to pool
View fieldoffset.cs
using System;
using System.Runtime.InteropServices;
namespace FieldOffsetSample
{
class Program
{
static void Main(string[] args)
{
MyStruct myStruct = default;
@GrabYourPitchforks
GrabYourPitchforks / improving_dev_experience.md
Last active Oct 28, 2020
Improving the developer experience with regard to default string globalization
View improving_dev_experience.md

Improving the developer experience with regard to default string globalization

Note: This is a companion document to dotnet/docs#21249, which discusses the behaviors as they currently exist. It's assumed the reader is generally familiar with that document.

Summary

Since .NET 5 standardized on using ICU instead of NLS for globalization across all supported platforms (see breaking change notice), we've received a few reports of string and globalization APIs not behaving as expected.

These reports generally fall into one of two buckets:

@GrabYourPitchforks
GrabYourPitchforks / print_skeleton.cs
Created Oct 21, 2020
Print a class skeleton from an implementation
View print_skeleton.cs
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Linq;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace ConsoleAppDumpCryptoApis
{
@GrabYourPitchforks
GrabYourPitchforks / binder_sample.cs
Created Aug 14, 2020
BinaryFormatter binder sample
View binder_sample.cs
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
class Program
{
static void Main(string[] args)
{
Stream inputStream = GetInputStream();
@GrabYourPitchforks
GrabYourPitchforks / memorymarshal_cast_utf8.cs
Last active Feb 27, 2020
MemoryMarshal.Cast challenge
View memorymarshal_cast_utf8.cs
using System;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
static void Main(string[] args)
{
{
// the text below is meaningless
View mwi_module_initializer.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- ... -->
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- This task adds a module initializer to {IL}.txt. -->
<UsingTask TaskName="InjectModuleInitializer" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Path ParameterType="System.String" Required="true" />
<InitializerMethod ParameterType="System.String" Required="true" />
</ParameterGroup>