/// <summary> /// Try to get a message value for the base Exception constructor. If any of the arguments are invalid then return null and allow the constructor /// above to throw an ArgumentException when it identifies them. This should combine the brokenRuleException's message with the filename of the /// source file (if the content is Combined or Compiled then indicate this, likewise if it's identified as a Resets or Theme sheet). If the /// file is not the result of Combined or Compiled content then also include the line number which was identified as invalid (it won't /// mean anything for Combined or Compiled content, so don't bother for those). /// </summary> private static string TryToGetMessage( BrokenRuleEncounteredException brokenRuleException, StyleSheetTypeOptions styleSheetType, string relativePath) { if ((brokenRuleException == null) || !Enum.IsDefined(typeof(StyleSheetTypeOptions), styleSheetType) || string.IsNullOrWhiteSpace(relativePath)) { return(null); } var filename = relativePath; if (styleSheetType != StyleSheetTypeOptions.Other) { filename += "[" + styleSheetType + "]"; } var message = brokenRuleException.Message + " in " + filename; if ((styleSheetType != StyleSheetTypeOptions.Combined) && (styleSheetType != StyleSheetTypeOptions.Compiled)) { // SourceLineIndex is zero-based so add one to show line number message += " (line " + (brokenRuleException.Fragment.SourceLineIndex + 1) + ")"; } return(message); }
public BrokenRuleEncounteredInFileException( BrokenRuleEncounteredException brokenRuleException, StyleSheetTypeOptions styleSheetType, string relativePath) : base(TryToGetMessage(brokenRuleException, styleSheetType, relativePath) ?? "") { if (brokenRuleException == null) { throw new ArgumentNullException("brokenRuleException"); } if (!Enum.IsDefined(typeof(StyleSheetTypeOptions), styleSheetType)) { throw new ArgumentOutOfRangeException("styleSheetType"); } if (string.IsNullOrWhiteSpace(relativePath)) { throw new ArgumentException("Null/blank relativePath specified"); } BrokenRuleException = brokenRuleException; StyleSheetType = styleSheetType; RelativePath = relativePath; }