MediaTypeHeaderValue accepts a list of strings instead of a list of StringSegments
jkotalik opened this issue · 8 comments
With our efforts to remove usages of strings in favor of string segments, it seems incomplete that MediaTypeHeaderValue.ParseList only accepts a list of strings rather than a list of StringSegment. We should consider adding an overload to accept a list of StringSegment too.
Relates to the ongoing effort of #718 and merging MediaType with MediaTypeHeaderValue.
Do you have a usage? This was left for compatibility with headers as StringValues which is a list of strings.
The only list method which is actually used in HttpAbstractions is TryParseList (in HeaderDictionaryTypeExtensions). I understand why this is method is here, however it seems backwards to have TryParse accept a StringSegment and TryParseList accept a List<string>.
StringValues has implicit converters to and from string and string[], but not StringSegment or StringSegment[]. As parse is performance sensitive we didn't want to add implicit converters that would hide SubString calls.
That said, yes you could have a TryParseList overload of IList<StringSegment> we just don't have any usage scenarios for it yet.
Should we consider adding an implicit converter between StringSegment and StringValue? And it wouldn't be much work to add overloads for StringSegment if we would like to. Though we not have a usage scenario, the method is public.
We don't want the implicit converter from StringSegment to StringValue, it may be required to call SubString.
This issue was moved to dotnet/aspnetcore#2695