{"action":"closed","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/28594","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/28594/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/28594/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/28594/events","html_url":"https://github.com/dotnet/corefx/issues/28594","id":309748335,"node_id":"MDU6SXNzdWUzMDk3NDgzMzU=","number":28594,"title":"Proposal: new System.ComponentModel.VersionConverter class","user":{"login":"0xced","id":51363,"node_id":"MDQ6VXNlcjUxMzYz","avatar_url":"https://avatars3.githubusercontent.com/u/51363?v=4","gravatar_id":"","url":"https://api.github.com/users/0xced","html_url":"https://github.com/0xced","followers_url":"https://api.github.com/users/0xced/followers","following_url":"https://api.github.com/users/0xced/following{/other_user}","gists_url":"https://api.github.com/users/0xced/gists{/gist_id}","starred_url":"https://api.github.com/users/0xced/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0xced/subscriptions","organizations_url":"https://api.github.com/users/0xced/orgs","repos_url":"https://api.github.com/users/0xced/repos","events_url":"https://api.github.com/users/0xced/events{/privacy}","received_events_url":"https://api.github.com/users/0xced/received_events","type":"User","site_admin":false},"labels":[{"id":163655927,"node_id":"MDU6TGFiZWwxNjM2NTU5Mjc=","url":"https://api.github.com/repos/dotnet/corefx/labels/api-approved","name":"api-approved","color":"159818","default":false},{"id":167509096,"node_id":"MDU6TGFiZWwxNjc1MDkwOTY=","url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.ComponentModel","name":"area-System.ComponentModel","color":"d4c5f9","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/dotnet/corefx/milestones/5","html_url":"https://github.com/dotnet/corefx/milestone/5","labels_url":"https://api.github.com/repos/dotnet/corefx/milestones/5/labels","id":1328080,"node_id":"MDk6TWlsZXN0b25lMTMyODA4MA==","number":5,"title":"Future","description":"Milestone tracking issues not triaged to a planned release. Work in this milestone may happen, or may not: it is not committed.","creator":{"login":"joshfree","id":1302850,"node_id":"MDQ6VXNlcjEzMDI4NTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1302850?v=4","gravatar_id":"","url":"https://api.github.com/users/joshfree","html_url":"https://github.com/joshfree","followers_url":"https://api.github.com/users/joshfree/followers","following_url":"https://api.github.com/users/joshfree/following{/other_user}","gists_url":"https://api.github.com/users/joshfree/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfree/subscriptions","organizations_url":"https://api.github.com/users/joshfree/orgs","repos_url":"https://api.github.com/users/joshfree/repos","events_url":"https://api.github.com/users/joshfree/events{/privacy}","received_events_url":"https://api.github.com/users/joshfree/received_events","type":"User","site_admin":false},"open_issues":1864,"closed_issues":235,"state":"open","created_at":"2015-09-29T00:25:45Z","updated_at":"2018-09-27T07:29:31Z","due_on":null,"closed_at":null},"comments":8,"created_at":"2018-03-29T13:10:21Z","updated_at":"2018-09-27T07:29:30Z","closed_at":"2018-09-27T07:29:30Z","author_association":"CONTRIBUTOR","body":"## Rationale and Usage\r\n\r\nConverting between `System.Version` and `string` is currently not supported using a `System.ComponentModel.TypeConverter`. Many system types are supported out of the box (System.DateTimeOffset, System.Guid, System.TimeSpan, System.Uri etc.) so I think System.Version would be a welcome addition.\r\n\r\nI was expecting this to work, but converting from string actually throws `NotSupportedException`: TypeConverter cannot convert from System.String.\r\n\r\n```csharp\r\nusing System.ComponentModel;\r\nusing System.Diagnostics;\r\nTypeConverter versionConverter = TypeDescriptor.GetConverter(typeof(Version));\r\nVersion version = versionConverter.ConvertFromString(\"1.2.3.4\") as Version;\r\nTrace.Assert(version.Major == 1);\r\nTrace.Assert(version.Minor == 2);\r\nTrace.Assert(version.Build == 3);\r\nTrace.Assert(version.Revision == 4);\r\n```\r\n\r\n## Proposed API\r\n\r\n```csharp\r\npublic partial class VersionConverter : System.ComponentModel.TypeConverter\r\n{\r\n    public VersionConverter();\r\n    public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType);\r\n    public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType);\r\n    public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value);\r\n    public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType);\r\n    public override bool IsValid(System.ComponentModel.ITypeDescriptorContext context, object value);\r\n}\r\n```\r\n\r\n## Details\r\n\r\nConverting between `string` and `System.Version` is very straightforward, implementation would be very similar to `GuidConverter` or `UriTypeConverter`.\r\n\r\n\r\n## Open Questions\r\n\r\n* What exception should be thrown when the string to convert is not valid, for example `\"1\"`? Other converters just let the constructor of the type throw the exception.\r\n\r\n```csharp\r\nvar uriConverter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Uri));\r\nuriConverter.ConvertFromString(\"mailto:User@\"); // throws UriFormatException\r\n```\r\n\r\n```csharp\r\nvar guidConverter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Guid));\r\nguidConverter.ConvertFromString(\"xxxx\"); // throws FormatException\r\n```\r\n\r\nFor `System.Version`, that would mean throwing an `ArgumentException` which is less descriptive than a `FormatException`.\r\n\r\n* Should the converter be registered with other `IntrinsicTypeConverters` (is System.Version an intrinsic type?) or should the converter be registered with the `TypeConverterAttribute` on the `System.Version` class?\r\n\r\n## Pull Request\r\n\r\nA pull request with the proposed changes is available: #28516\r\n"}}
{"actor":{"display_login":"0xced"}}