我觉得这可能是一个愚蠢的问题,但是我无法得出我确定存在的简单解决方案。
我有一个C#类,可以针对其他文件来验证配置文件。
可能存在两种错误,这些错误在枚举中表示:
public enum ErrorType
{
VersionsMismatch,
UnsupportedCombination
}
有一个表示错误的结构:
public struct ValiditionResult
{
public bool Valid { get; set; }
public string ErrorMessage { get; set; }
public ErrorType ErrorType { get; set; }
public List<ConfProperties> InvalidProperties {get;set;}
}
函数界面如下所示:
public ValiditionResult Validate(string confFile, string progFile)
该结构表示文件中所需的修复程序。
因此,如果有两种类型的修复程序,则应指定它。
指示所有已发生错误的最佳方法是什么(将来可能会发生两个以上错误)?
要返回ValidationResult结构的列表?对枚举进行异或运算?还有其他想法吗?
最佳答案
您可以使用属性[Flags]标记枚举
有关更多信息,请参见http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx。
关于c# - C#: Handling combination of errors in return value,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10321097/