/// <summary> /// Initialises a new instance of <see cref="TemplateCompilationException"/>. /// </summary> /// <param name="errors">The set of compiler errors.</param> /// <param name="sourceCode">The source code that wasn't compiled.</param> /// <param name="template">The source template that wasn't compiled.</param> internal TemplateCompilationException(CompilerErrorCollection errors, string sourceCode, string template) : base("Unable to compile template. " + errors[0].ErrorText + "\n\nOther compilation errors may have occurred. Check the Errors property for more information.") { var list = errors.Cast<CompilerError>().ToList(); Errors = new ReadOnlyCollection<CompilerError>(list); SourceCode = sourceCode; Template = template; }
/// <summary> /// Initialises a new instance of <see cref="TemplateCompilationException"/> /// </summary> /// <param name="errors">The collection of compilation errors.</param> public TemplateCompilationException(CompilerErrorCollection errors) : base("Unable to compile template. Check the Errors list for details.") { var list = errors.Cast<CompilerError>().ToList(); Errors = new ReadOnlyCollection<CompilerError>(list); }
/// <summary> /// Converts a <see cref="CompilerErrorCollection"/> to a collection of <see cref="BindingExpressionCompilationError"/> objects. /// </summary> /// <param name="state">The expression compiler's current state.</param> /// <param name="models">The list of models which were compiled.</param> /// <param name="errors">The collection of errors produced during compilation.</param> /// <returns>A list containing the converted errors.</returns> private static List<BindingExpressionCompilationError> CreateBindingExpressionCompilationErrors(ExpressionCompilerState state, IEnumerable<DataSourceWrapperInfo> models, CompilerErrorCollection errors) { var result = new List<BindingExpressionCompilationError>(); var workingDirectory = GetWorkingDirectory(state); var errorsByFile = errors.Cast<CompilerError>() .Where(x => !x.IsWarning).GroupBy(x => Path.GetFileName(x.FileName)).ToDictionary(x => x.Key, x => x.ToList()); foreach (var model in models) { var dataSourceWrapperFilename = Path.GetFileName(GetWorkingFileForDataSourceWrapper(model)); var dataSourceErrors = default(List<CompilerError>); if (errorsByFile.TryGetValue(dataSourceWrapperFilename, out dataSourceErrors)) { foreach (var dataSourceError in dataSourceErrors) { var fullPathToFile = model.DataSourceWrapperName; if (state.WriteErrorsToFile) { fullPathToFile = Path.GetFullPath(Path.Combine(workingDirectory, Path.ChangeExtension(model.DataSourceWrapperName, "cs"))); } result.Add(new BindingExpressionCompilationError(fullPathToFile, dataSourceError.Line, dataSourceError.Column, dataSourceError.ErrorNumber, dataSourceError.ErrorText)); } } } return result; }
internal TemplateCompilationException(CompilerErrorCollection errorCollection) : base(GetMessage(errorCollection)) { _errors = new ReadOnlyCollection<CompilerError>(errorCollection.Cast<CompilerError>().ToArray()); }
public ConfigurationCompilationException(ConfigurationFileInfo configuration, CompilerErrorCollection compilationErrors) : this(configuration, compilationErrors.Cast<CompilerError>()) { }
private static void AssertSingleError(CompilerErrorCollection errors, params string[] keywords) { var error = errors.Cast<CompilerError>().Single(); foreach (string keyword in keywords) { StringAssert.Contains(error.ErrorText, keyword); } }
/// <summary> /// Initialises a new instance of <see cref="TemplateException"/> /// </summary> /// <param name="errors">The collection of compilation errors.</param> internal TemplateException(CompilerErrorCollection errors) : base("Unable to compile template.") { var list = errors.Cast<CompilerError>().ToList(); Errors = new ReadOnlyCollection<CompilerError>(list); }
private static string FormatMessage(CompilerErrorCollection errors) { var message = "One or more template processing errors occurred: " + Environment.NewLine; message += string.Join(Environment.NewLine, errors.Cast<CompilerError>().Select(x => x.ToString())); return message; }