I'm passing a List of Custom Objects to my Custom Exception Class and need to display all the objects in the message. How can I do this?
public class MissingUnitSNSException : Exception
{
public MissingUnitSNSException()
{
}
public MissingUnitSNSException(List<UnitViewModel> missingsns)
: base(String.Format("Serial Numbers not found: {0}", missingsns))
{
}
}
The error tells me the type of object, but I need the serial number attribute that's tied to each object in the list.
How about replacing missingsns
with a string of comma separated serial numbers. Like so:
string.join(", ", missingsns.Select(sns => sns.SerialNumber.ToString()))
This should list out the serial numbers like: A01, B01, C02, ...
Full line:
public MissingUnitSNSException(List<UnitViewModel> missingsns)
: base(String.Format("Serial Numbers not found: {0}",
string.join(", ", missingsns.Select(sns => sns.SerialNumber.ToString()))))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments