本文整理汇总了C#中System.CodeDom.Compiler.CompilerErrorCollection类的典型用法代码示例。如果您正苦于以下问题:C# CompilerErrorCollection类的具体用法?C# CompilerErrorCollection怎么用?C# CompilerErrorCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompilerErrorCollection类属于System.CodeDom.Compiler命名空间,在下文中一共展示了CompilerErrorCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileAssemblyFromFile
public override CompilerResults CompileAssemblyFromFile(CompilerParameters options, params string[] fileNames)
{
var units = new CodeCompileUnit[fileNames.Length];
var errors = new CompilerErrorCollection();
var syntax = new Parser(options);
for (int i = 0; i < fileNames.Length; i++)
{
try
{
units[i] = syntax.Parse(new StreamReader(fileNames[i]), fileNames[i]);
}
#if !DEBUG
catch (ParseException e)
{
errors.Add(new CompilerError(e.Source, e.Line, 0, e.Message.GetHashCode().ToString(), e.Message));
}
catch (Exception e)
{
errors.Add(new CompilerError { ErrorText = e.Message });
}
#endif
finally { }
}
var results = CompileAssemblyFromDom(options, units);
results.Errors.AddRange(errors);
return results;
}
示例2: HandleException
private void HandleException(Exception ex, ProjectFile file, SingleFileCustomToolResult result)
{
if (ex is SpecFlowParserException)
{
SpecFlowParserException sfpex = (SpecFlowParserException) ex;
if (sfpex.ErrorDetails == null || sfpex.ErrorDetails.Count == 0)
{
result.UnhandledException = ex;
}
else
{
var compilerErrors = new CompilerErrorCollection();
foreach (var errorDetail in sfpex.ErrorDetails)
{
var compilerError = new CompilerError(file.Name, errorDetail.ForcedLine, errorDetail.ForcedColumn, "0", errorDetail.Message);
compilerErrors.Add(compilerError);
}
result.Errors.AddRange(compilerErrors);
}
}
else
{
result.UnhandledException = ex;
}
}
示例3: Emit
public void Emit(CompilerErrorCollection errors, MethodBuilder m)
{
//Set the parameters
//ParameterBuilder[] parms = new ParameterInfo[args.Length];
for(int i = 0; i < args.Length; i++)
m.DefineParameter(i + 1, ParameterAttributes.None, args[i].Name);
ILGenerator gen = m.GetILGenerator();
//Define the IT variable
LocalRef it = locals["IT"] as LocalRef;
DefineLocal(gen, it);
statements.Process(this, errors, gen);
statements.Emit(this, gen);
//Cast the IT variable to our return type and return it
if (m.ReturnType != typeof(void))
{
gen.Emit(OpCodes.Ldloc, it.Local);
Expression.EmitCast(gen, it.Type, m.ReturnType);
}
gen.Emit(OpCodes.Ret);
}
示例4: TemplateCompilationException
/// <summary>
/// Creates a new instance with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized
/// object data.</param>
/// <param name="context">The contextual information about
/// the source or destination.</param>
protected TemplateCompilationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.errors = (CompilerErrorCollection) info.GetValue(
ErrorCollection,
typeof(CompilerErrorCollection));
}
示例5: Execute
public override bool Execute()
{
Errors = new CompilerErrorCollection();
try
{
AddAssemblyLoadEvent();
DoExecute();
}
catch (Exception ex)
{
RecordException(ex);
}
// handle errors
if (Errors.Count > 0)
{
bool hasErrors = false;
foreach (CompilerError error in Errors)
{
if (error.IsWarning)
OutputWarning(error.ToString(), error.ErrorText, error.FileName, error.Line, error.Column);
else
{
OutputError(error.ToString(), error.ErrorText, error.FileName, error.Line, error.Column);
hasErrors = true;
}
}
return !hasErrors;
}
return true;
}
示例6: AssemblyGenerator
/// <summary>
/// Creates a new instance of the Brainfuck assembly generator.
/// </summary>
public AssemblyGenerator()
{
Debug = false;
Name = DefaultName;
Errors = new CompilerErrorCollection();
Cells = 1024;
}
示例7: CompileCSharpScript
/// <summary>
/// Compiles a C# script as if it were a file in your project.
/// </summary>
/// <param name="scriptText">The text of the script.</param>
/// <param name="errors">The compiler errors and warnings from compilation.</param>
/// <param name="assemblyIfSucceeded">The compiled assembly if compilation succeeded.</param>
/// <returns>True if compilation was a success, false otherwise.</returns>
public static bool CompileCSharpScript(string scriptText, out CompilerErrorCollection errors, out Assembly assemblyIfSucceeded)
{
var codeProvider = new CSharpCodeProvider();
var compilerOptions = new CompilerParameters();
// We want a DLL and we want it in memory
compilerOptions.GenerateExecutable = false;
compilerOptions.GenerateInMemory = true;
// Add references for UnityEngine and UnityEditor DLLs
compilerOptions.ReferencedAssemblies.Add(typeof(Vector2).Assembly.Location);
compilerOptions.ReferencedAssemblies.Add(typeof(EditorApplication).Assembly.Location);
// Default to null output parameters
errors = null;
assemblyIfSucceeded = null;
// Compile the assembly from the source script text
CompilerResults result = codeProvider.CompileAssemblyFromSource(compilerOptions, scriptText);
// Store the errors for the caller. even on successful compilation, we may have warnings.
errors = result.Errors;
// See if any errors are actually errors. if so return false
foreach (CompilerError e in errors) {
if (!e.IsWarning) {
return false;
}
}
// Otherwise we pass back the compiled assembly and return true
assemblyIfSucceeded = result.CompiledAssembly;
return true;
}
示例8: FillErrorList
public void FillErrorList( CompilerErrorCollection errors )
{
_listErrors.Items.Clear( );
_listWarnings.Items.Clear( );
if( errors != null && errors.Count > 0 )
{
int errorNum = 0;
foreach( CompilerError error in errors )
{
ListViewItem item = new ListViewItem( );
//Error Number
errorNum++;
item.SubItems.Add( new ListViewItem.ListViewSubItem( item, errorNum.ToString( ) ) );
//Error Message
item.SubItems.Add( new ListViewItem.ListViewSubItem( item, error.ErrorText ) );
//Filename
item.SubItems.Add( new ListViewItem.ListViewSubItem( item, System.IO.Path.GetFileName( error.FileName ) ) );
//Line
item.SubItems.Add( new ListViewItem.ListViewSubItem( item, error.Line.ToString( ) ) );
//Column
item.SubItems.Add( new ListViewItem.ListViewSubItem( item, error.Column.ToString( ) ) );
if( error.IsWarning )
_listWarnings.Items.Add( item );
else
_listErrors.Items.Add( item );
}
}
}
示例9: CompileCSharpImmediateSnippet
/// <summary>
/// Compiles a method body of C# script, wrapped in a basic void-returning method.
/// </summary>
/// <param name="methodText">The text of the script to place inside a method.</param>
/// <param name="errors">The compiler errors and warnings from compilation.</param>
/// <param name="methodIfSucceeded">The compiled method if compilation succeeded.</param>
/// <returns>True if compilation was a success, false otherwise.</returns>
public static bool CompileCSharpImmediateSnippet(string methodText, out CompilerErrorCollection errors, out MethodInfo methodIfSucceeded)
{
// Wrapper text so we can compile a full type when given just the body of a method
string methodScriptWrapper = @"
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Linq;
public static class CodeSnippetWrapper
{{
public static void PerformAction()
{{
{0};
}}
}}";
// Default method to null
methodIfSucceeded = null;
// Compile the full script
Assembly assembly;
if (CompileCSharpScript(string.Format(methodScriptWrapper, methodText), out errors, out assembly))
{
// If compilation succeeded, we can use reflection to get the method and pass that back to the user
methodIfSucceeded = assembly.GetType("CodeSnippetWrapper").GetMethod("PerformAction", BindingFlags.Static | BindingFlags.Public);
return true;
}
// Compilation failed, caller has the errors, return false
return false;
}
示例10: TraceErrors
private static void TraceErrors(CompilerErrorCollection errors)
{
foreach (var error in errors)
{
Trace.WriteLine(error);
}
}
示例11: StartProcessingRun
public override void StartProcessingRun (CodeDomProvider languageProvider, string templateContents, CompilerErrorCollection errors)
{
base.StartProcessingRun (languageProvider, templateContents, errors);
provider = languageProvider;
postStatements.Clear ();
members.Clear ();
}
示例12: HandleErrors
static void HandleErrors(CompilerErrorCollection cr)
{
for(var i = 0; i < cr.Count; i++)
Tracer.Line(cr[i].ToString());
throw new CSharpCompilerErrorException(cr);
}
示例13: Main
public static void Main()
{
var engine = new ScriptEngine();
CompilerErrorCollection err = new CompilerErrorCollection();
engine.Run("Console.WriteLine(\"Hello, Script!\");", out err);
}
示例14: TemplateCompilationException
/// <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;
}
示例15: ShowErrors
public void ShowErrors(CompilerErrorCollection errors)
{
TaskService.ClearExceptCommentTasks();
foreach (CompilerError error in errors) {
TaskService.Add(new CompilerErrorTask(error));
}
SD.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront();
}