Okay, let's say with have this:
string productUidsPostValue =
"693C850B-2B0B-4429-98F8-AE99E92991A8,F37858BD-22E5-4077-BADD-9AFCDCC92628";
I want to turn this into a List the easiest way possible. And of course, the strings in productUidsPostValue
need to be strongly typed as Guid
s if they are valid Guid
s. This is the code I have written. Surely it can be refactored or reduced, right?
if (string.IsNullOrEmpty(productUidsPostValue))
{
throw new InvalidOperationException
("this.Request.Form['CheckoutProductUids'] cannot be null or empty.");
}
var seperatedUids = productUidsPostValue.Split(',');
var productUids = new List<Guid>(seperatedUids.Length);
Guid guid;
foreach (var productUid in seperatedUids)
{
// Please upvote Gishu if you are reading this
if (!GuidHelper.TryParse(productUid, out guid))
{
productUids.Add(guid);
}
}