Search

GuidConverter does not implement IsValid by kzu

Active

11
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 96296
Opened: 12/23/2004 10:26:26 AM
Access Restriction: Public
0
Workaround(s)
6
User(s) can reproduce this bug
Converters can be used to check a value instead of directly trying the ConvertFrom and catching any exceptions that may happen.

The GuidConverter, however, does not implement the IsValid method and we can only tell if a value is valid by trying the conversion which basically tries to construct a Guid object which will throw if the input string is not valid.
Details (expand)
Product Language
English
Version
Visual Studio 2005 Beta 1
Category
Base Class Libraries and APIs
Subcategory
 
Operating System
Windows XP Professional
Steps to Reproduce
TypeConverter conv = TypeDescriptor.GetConverter(typeof(Guid));
string g = "an invalid guid";

// Passes
if (conv.IsValid(g))
{
// Throws
Guid guid = (Guid)conv.ConvertFrom(g);
}
Actual Results
An exception is thrown even if the IsValid method returns true.
Expected Results
Don't pass the IsValid test if the string is not a valid GUID up-front. At least an initial check can be implemented pretty trivially with a regex.
File Attachments
0 attachments
Sign in to post a comment.
Posted by TAG on 12/23/2004 at 1:00 PM
Kzu,

I believe your suggestion directly related to FDBK11640 Guid.TryParse.
Due to limited availability of TryParse (or even IsValid) methods - TypeConverter.IsValid actualy implemented only in few converters: like a EnumConverter or UriTypeConverter.

But it's NOT implemented even to such an trivial convertors like a DateTimeConverter , TimeSpanConverter, BooleanConverter :-((

I believe that your suggestion must be addressed

--
Andriy G. Tereshchenko
Odessa, Ukraine
Posted by Microsoft on 1/5/2005 at 1:33 AM
The Microsoft Sub-status is now "Reproduced"

Thanks for reporting this bug, we have been able to repro this issue and are investigating.
Posted by Microsoft on 1/6/2005 at 10:18 AM
This is a good suggestion. Unfortunately we will not be able to implement IsValid in the Whidbey timeframe. We will consider this for a future release.
Posted by Microsoft on 10/24/2005 at 6:14 PM
This issue has been reactivated as we begin planning for the next version of Visual Studio. Over the coming months we will reconsider feedback that was previously postponed. We welcome your comments and participation in this process.

-- Visual Studio Team
Posted by IDisposable on 4/13/2009 at 6:16 PM
So, going on 5 years, can we add this TRIVIAL method to the Guid class and eliminate huge numbers of Exceptions?