K
kidders
Hi guys,
I'm trying to work out how to replicate the following in linq. I have
most of it the bit im stuck on is how to implement a try catch, and
that if an exception is caught the object doesnt get added to the
collection.
original code
List<ParkHireType> result = new List<ParkHireType>();
foreach (XElement node in
availableHire.Root.Elements("RENTAVAILABILITY"))
{
try
{
if (node.Attribute("code").Value == OfferCode)
{
result.Add(ParkHireType.Load(node));
}
}
catch (ParkHireTypeException)
{
//do something
}
}
return result;
linq so far:
return availableHire.Root.Elements("RENTALAVAILABILITY")
.Where(node =>
node.Elements("OFFER").Attributes("code").ElementAt(0).Value ==
OfferCode)
.Select(node => ParkHireType.Load(node))
.ToList<ParkHireType>();
thanks for any help
I'm trying to work out how to replicate the following in linq. I have
most of it the bit im stuck on is how to implement a try catch, and
that if an exception is caught the object doesnt get added to the
collection.
original code
List<ParkHireType> result = new List<ParkHireType>();
foreach (XElement node in
availableHire.Root.Elements("RENTAVAILABILITY"))
{
try
{
if (node.Attribute("code").Value == OfferCode)
{
result.Add(ParkHireType.Load(node));
}
}
catch (ParkHireTypeException)
{
//do something
}
}
return result;
linq so far:
return availableHire.Root.Elements("RENTALAVAILABILITY")
.Where(node =>
node.Elements("OFFER").Attributes("code").ElementAt(0).Value ==
OfferCode)
.Select(node => ParkHireType.Load(node))
.ToList<ParkHireType>();
thanks for any help