Last active
May 27, 2022 22:58
-
-
Save GrabYourPitchforks/c8294bbec273cb4c169c456dc8744339 to your computer and use it in GitHub Desktop.
Type name parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
public override int GetHashCode(); | |
public override bool Equals(object? other); | |
public override bool Equals(PublicKeyToken? other); | |
public static bool operator==(PublicKeyToken? other); | |
} | |
// https://github.com/dotnet/arcade/blob/e7ede87875f41a9b3df898ae08da5ebc96e24f56/src/Microsoft.DotNet.Arcade.Sdk/tools/StrongName.targets#L23-L76 | |
public static class WellKnownPublicKeyTokens | |
{ | |
// b03f5f7f11d50a3a, frequently used by MSFT OSS projects | |
public static PublicKeyToken Microsoft { get; } | |
// 31BF3856AD364E35, used by netfx 3.0 and later | |
public static PublicKeyToken MicrosoftShared { get; } | |
// adb9793829ddae60, used by asp.net core | |
public static PublicKeyToken MicrosoftAspNetCore { get; } | |
// b77a5c561934e089, used by mscorlib and similar | |
public static PublicKeyToken ECMA { get; } | |
// 7cec85d7bea7798e, used by System.Private.CoreLib | |
public static PublicKeyToken SilverlightPlatform { get; } | |
} | |
public sealed class AssemblyId : IEquatable<AssemblyId> | |
{ | |
public AssemblyId(string assemblyString); | |
public AssemblyId(ReadOnlySpan<char> assemblyString); | |
public AssemblyId(Assembly assembly); | |
public AssemblyId(AssemblyName assemblyName); | |
public string Name { get; } | |
public Version? Version { get; } | |
public string? Culture { get; } // This should be "neutral" by default, perhaps? | |
public PublicKeyToken? PublicKeyToken { get; } | |
public override int GetHashCode(); | |
public override bool Equals(object? other); | |
public override bool Equals(AssemblyId? other); | |
public static bool operator==(AssemblyId? other); | |
public AssemblyName ToAssemblyName(); // is it too dangerous to add this? | |
} | |
// Builder pattern? | |
public sealed class AssemblyIdBuilder | |
{ | |
public AssemblyIdBuilder(); | |
public AssemblyIdBuilder(string assemblyString); | |
public AssemblyIdBuilder(ReadOnlySpan<char> assemblyString); | |
public AssemblyIdBuilder(Assembly assembly); | |
public AssemblyIdBuilder(AssemblyName assemblyName); | |
public AssemblyIdBuilder(AssemblyId assemblyId); | |
public string Name { get; set; } // nullable considerations? | |
public Version? Version { get; set; } | |
public string? Culture { get; set; } // nullable considerations? | |
public PublicKeyToken? PublicKeyToken { get; set; } | |
public AssemblyId Build(); | |
} | |
public sealed class TypeId : IEquatable<TypeId> | |
{ | |
public TypeId(string fullTypeName); | |
public TypeId(string fullTypeName, string assemblyName); | |
public TypeId(ReadOnlySpan<char> fullTypeName); | |
public TypeId(ReadOnlySpan<char> fullTypeName, ReadOnlySpan<char> assemblyName); | |
public TypeId(Type type); | |
public string Name { get; } | |
public bool IsGenericType { get; } | |
public bool IsGenericTypeDefinition { get; } | |
public int GenericParameterCount { get; } | |
public TypeId[] GetGenericParameters(); | |
public AssemblyId? AssemblyId { get; } | |
public override int GetHashCode(); | |
public override bool Equals(object? other); | |
public override bool Equals(TypeId? other); | |
public static bool operator==(TypeId? other); | |
// Do we need transforms? | |
// That is, every time you see <x> assembly, replace it with <y> instead? | |
public static TypeId ReplaceAssemblyIds(TypeId inputGraph, AssemblyId? searchFor, AssemblyId? replaceWith); | |
public static TypeId ReplaceAssemblyIds(TypeId inputGraph, Func<AssemblyId?, AssemblyId?> transformFunction); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment