The current fallback logic to extract the fullname bluntly assumes it is OK to split by , and then take the first part. While this works in some cases it fails with more advanced types like generics. We are aware that generic are not officially supported, but regardless of that, the parsing logic should treat the assembly qualified names properly and not lead to invalid data types.
Instead of string splitting or trying to do a fancy regular expression match and replace (with all the consequences of those potentially timing out etc.), I came up with a straightforward approach that should be robust and reliable (see test cases) and even in the cases when we get a full name already even faster since we are not attempting to split that also involves an unnecessary array allocation.
Benchmark
```csharp
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
namespace MicroBenchmarks.NServiceBus;
[SimpleJob]
[MemoryDiagnoser]
public class AssemblyQualifiedNameParser
{
[Benchmark(Baseline = true)]
[ArgumentsSource(nameof(Arguments))]
public string Before(string messageIdentifier) => GetMessageTypeNameWithoutAssemblyOld(messageIdentifier);
[Benchmark]
[ArgumentsSource(nameof(Arguments))]
public string After(string messageIdentifier) => GetMessageTypeNameWithoutAssembly(messageIdentifier);
public IEnumerable
The current fallback logic to extract the fullname bluntly assumes it is OK to split by
,
and then take the first part. While this works in some cases it fails with more advanced types like generics. We are aware that generic are not officially supported, but regardless of that, the parsing logic should treat the assembly qualified names properly and not lead to invalid data types.Instead of string splitting or trying to do a fancy regular expression match and replace (with all the consequences of those potentially timing out etc.), I came up with a straightforward approach that should be robust and reliable (see test cases) and even in the cases when we get a full name already even faster since we are not attempting to split that also involves an unnecessary array allocation.
Benchmark