Since Guid.TryParse isn't supported yet, I usually just wrap the Guid parse in a try/catch block
Code: Select all
Guid guid = Guid.Empty;
var success = false;
try {
guid = Guid.Parse(someValue);
success = true;
} catch { }
if (success) {
//do something with guid
}
BUT, in the JS output, sometimes with an empty or null string, Guid.Parse is successful and gives me a malformed Guid:
Code: Select all
00000NaN-0NaN-0NaN-NaNNaN-NaNNaNNaNNaNNaNNaN
so now, I have to do this:
Code: Select all
Guid guid = Guid.Empty;
var success = false;
try {
guid = Guid.Parse(someValue);
if(!guid.ToString().Contains("NaN"))
success = true;
} catch { }
if (success) {
//do something with guid
}