-
Notifications
You must be signed in to change notification settings - Fork 168
Open
Description
I am dealing with parsing and validating xml and I wanted to avoid throw, so I decided to try OneOf, but how do I correctly handle multiple nested OneOf.Match() to not make them look like a ladder?
For example this - each call can result in XmlException being returned instead of whatever I want.
ValidationResult ValidateXML (string xml)
{
XDocument doc = ParseIntoXDoc(xml);
Version ver = ExtractVersion(doc);
return ValidateXML(ver, doc);
}Normally I would just have if after everything to check if I got null due to whatever reason, but OneOf simplifies it to this:
ValidationResult ValidateXML (string xml)
{
return ParseIntoXDoc(xml).Match(
ex => ValidationResult(ex),
doc => ExtractVersion(doc).Match(
ex => ValidationResult(ex),
ver => ValidateXML(ver, doc);
));
}After a few more checks like above it will look like if "ladder" and I really dislike that. Is there a more elegant solution to this?
emperador-ming
Metadata
Metadata
Assignees
Labels
No labels