In your example there would be nothing to return if value
where not one of the handled cases. You need to specify a return value for ALL cases or throw an exception for invalid values. One way to do this is by using the default
case in your switch
statement. Here is an example:
public class EventCode
{
public static string ToXml(Soap.EventCode.EvCodes value)
{
switch (value)
{
case Soap.EventCode.EvCodes.DispatchedForDelivery:
case Soap.EventCode.EvCodes.Delivered:
return "OD";
case Soap.EventCode.EvCodes.DepartedFromTerminal:
return "L1";
// Catch-all for all other cases.
// Throwing an exception here is just an example implementation, not mandatory.
default: throw new ArgumentOutOfRangeException(nameof(value), "Unsupported Evcode: " + value);
}
}
}