Proposal: new System.ComponentModel.EncodingConverter class #27489
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.ComponentModel
Milestone
Rationale and Usage
Converting between
System.Text.Encoding
andstring
orint
is currently not supported using aSystem.ComponentModel.TypeConverter
. Many system types are supported out of the box (System.DateTimeOffset, System.Guid, System.TimeSpan, System.Uri, System.Version etc.) so I think System.Text.Encoding would be a welcome addition.I was expecting this to work, but converting from string or int actually throws a
NotSupportedException
.Proposed API
Details
Converting from
string
orint
toSystem.Text.Encoding
is straightforward usingEncoding.GetEncoding
, implementation would be very similar to theVersionConverter
pull request (dotnet/corefx#28516) merged about one month ago.Open Questions
int
(interpreted as a code page) be supported ? I started writing unit tests and noticed a lot of edge cases:int
, should we also support conversion from all types implicitly convertible toint
, i.e.sbyte
,byte
,short
,ushort
andchar
? (Yes in my opinion)int
, should we support conversion from larger types, such aslong
when the value fits an int, e.g.long codePage = 1200
. (Yes in my opinion)int
, should we support conversion int as string, e.g.string codePage = "1200"
? (This is where I started to wonder if supporting conversion fromint
was a good idea at all)Pull Request
A pull request with the proposed changes is available: dotnet/corefx#32527
The text was updated successfully, but these errors were encountered: