本文整理汇总了C#中System.CodeDom.Compiler.CompilerResults类的典型用法代码示例。如果您正苦于以下问题:C# CompilerResults类的具体用法?C# CompilerResults怎么用?C# CompilerResults使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilerResults类属于System.CodeDom.Compiler命名空间,在下文中一共展示了CompilerResults类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <exception cref="TargetInvocationException">When the supplied assembly's main method throws</exception>
public void Execute(CompilerResults results, IEnumerable<string> additionalReferences)
{
var entryPoint = results.CompiledAssembly.EntryPoint;
using(serviceMessages.ProgressBlock("Executing script"))
ExecutePrivate(entryPoint, additionalReferences);
}
示例2: CompileAssemblyFromDomBatch
public CompilerResults CompileAssemblyFromDomBatch(CompilerParameters options, CodeCompileUnit[] compilationUnits)
{
Setup(options, ContainsLocalFunctions(compilationUnits));
foreach(var Unit in compilationUnits)
{
foreach (CodeAttributeDeclaration attribute in Unit.AssemblyCustomAttributes)
EmitAttribute(ABuilder, attribute);
EmitNamespace(ABuilder, Unit.Namespaces[0]);
}
ABuilder.SetEntryPoint(EntryPoint, PEFileKinds.WindowApplication);
Save();
var results = new CompilerResults(new TempFileCollection());
string output = options.OutputAssembly;
if (options.GenerateInMemory)
{
results.TempFiles.AddFile(output, false);
byte[] raw = File.ReadAllBytes(output);
results.CompiledAssembly = Assembly.Load(raw);
File.Delete(output);
}
else
results.PathToAssembly = Path.GetFullPath(output);
return results;
}
示例3: Compile
public List<CheckingResult> Compile(string program, out CompilerResults compilerResults)
{
compilerResults = null;
using (var provider = new CSharpCodeProvider())
{
compilerResults = provider.CompileAssemblyFromSource(new CompilerParameters(new string[]
{
"System.dll"
})
{
GenerateExecutable = true
},
new string[]
{
program
});
}
var result = new List<CheckingResult>();
if (compilerResults.Errors.HasErrors)
{
for (int i = 0; i < compilerResults.Errors.Count; i++)
result.Add(new CheckingResult
{
FirstErrorLine = compilerResults.Errors[i].Line,
FirstErrorColumn = compilerResults.Errors[i].Column,
Output = null,
Description = compilerResults.Errors[i].ErrorText
});
}
return result;
}
示例4: Load
void Load (CompilerResults results, string fullName)
{
var assembly = results.CompiledAssembly;
Type transformType = assembly.GetType (fullName);
//MS Templating Engine does not look on the type itself,
//it checks only that required methods are exists in the compiled type
textTransformation = Activator.CreateInstance (transformType);
//set the host property if it exists
Type hostType = null;
var gen = host as TemplateGenerator;
if (gen != null) {
hostType = gen.SpecificHostType;
}
var hostProp = transformType.GetProperty ("Host", hostType ?? typeof(ITextTemplatingEngineHost));
if (hostProp != null && hostProp.CanWrite)
hostProp.SetValue (textTransformation, host, null);
var sessionHost = host as ITextTemplatingSessionHost;
if (sessionHost != null) {
//FIXME: should we create a session if it's null?
var sessionProp = transformType.GetProperty ("Session", typeof (IDictionary<string, object>));
sessionProp.SetValue (textTransformation, sessionHost.Session, null);
}
}
示例5: CompileScript
/// <summary>
/// Compile Script -> Return Assembly
/// </summary>
public Assembly CompileScript(IRefObject ScriptObject, out CompilerResults Result)
{
String ClassName, PrefixName;
switch (ScriptObject.Type)
{
case IRefObject.ScriptType.WEAPON:
ClassName = "ScriptWeapon";
PrefixName = "WeaponPrefix";
break;
default:
ClassName = "ScriptLevelNpc";
PrefixName = "LevelNpcPrefix";
break;
}
// Setup our options
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = false;
options.GenerateInMemory = true;
options.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Core.dll");
options.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
// Compile our code
CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider();
Result = csProvider.CompileAssemblyFromSource(options, "using CS_NPCServer; public class " + PrefixName + NextId[(int)ScriptObject.Type] + " : " + ClassName + " { public " + PrefixName + NextId[(int)ScriptObject.Type] + "(NPCServer Server, IRefObject Ref) : base(Server, Ref) { } " + ParseJoins(ScriptObject.Script) + " } ");
NextId[(int)ScriptObject.Type]++;
return (Result.Errors.HasErrors ? null : Result.CompiledAssembly);
}
示例6: CompilerErrorException
public CompilerErrorException(CompilerResults results)
{
foreach (CompilerError error in results.Errors)
{
this.CompilerMessage += error + "\n";
}
}
示例7: GetGeneratedType
public override Type GetGeneratedType(CompilerResults results)
{
Type type;
try
{
using (Stream stream = base.OpenStream())
{
XamlXmlReader reader2 = new XamlXmlReader(XmlReader.Create(stream));
while (reader2.Read())
{
if (reader2.NodeType == XamlNodeType.StartObject)
{
if (reader2.Type.IsUnknown)
{
StringBuilder sb = new StringBuilder();
this.AppendTypeName(reader2.Type, sb);
throw FxTrace.Exception.AsError(new TypeLoadException(System.Xaml.Hosting.SR.CouldNotResolveType(sb)));
}
return reader2.Type.UnderlyingType;
}
}
throw FxTrace.Exception.AsError(new HttpCompileException(System.Xaml.Hosting.SR.UnexpectedEof));
}
}
catch (XamlParseException exception)
{
throw FxTrace.Exception.AsError(new HttpCompileException(exception.Message, exception));
}
return type;
}
示例8: handleErrors
private void handleErrors(CompilerResults compilerResults)
{
if (compilerResults.Errors.Count > 0)
{
StringBuilder sb = new StringBuilder("Error compiling the composition script:\n");
foreach (CompilerError compilerError in compilerResults.Errors)
{
if (!compilerError.IsWarning)
{
sb.Append("\nError number:\t")
.Append(compilerError.ErrorNumber)
.Append("\nMessage:\t ")
.Append(compilerError.ErrorText)
.Append("\nLine number:\t")
.Append(compilerError.Line);
}
}
if (!sb.Length.Equals(0))
{
throw new PicoCompositionException(sb.ToString());
}
}
}
示例9: GetGeneratedType
internal Type GetGeneratedType(CompilerResults results, bool useDelayLoadTypeIfEnabled)
{
string str;
if (!this.Parser.RequiresCompilation)
{
return null;
}
if (this._instantiatableFullTypeName == null)
{
if (this.Parser.CodeFileVirtualPath == null)
{
return this.Parser.BaseType;
}
str = this._intermediateFullTypeName;
}
else
{
str = this._instantiatableFullTypeName;
}
if (useDelayLoadTypeIfEnabled && DelayLoadType.Enabled)
{
return new DelayLoadType(Util.GetAssemblyNameFromFileName(Path.GetFileName(results.PathToAssembly)), str);
}
return results.CompiledAssembly.GetType(str);
}
示例10: CacheCompileErrors
private void CacheCompileErrors(AssemblyBuilder assemblyBuilder, CompilerResults results)
{
System.Web.Compilation.BuildProvider provider = null;
foreach (CompilerError error in results.Errors)
{
if (!error.IsWarning)
{
System.Web.Compilation.BuildProvider buildProviderFromLinePragma = assemblyBuilder.GetBuildProviderFromLinePragma(error.FileName);
if (((buildProviderFromLinePragma != null) && (buildProviderFromLinePragma is BaseTemplateBuildProvider)) && (buildProviderFromLinePragma != provider))
{
provider = buildProviderFromLinePragma;
CompilerResults results2 = new CompilerResults(null);
foreach (string str in results.Output)
{
results2.Output.Add(str);
}
results2.PathToAssembly = results.PathToAssembly;
results2.NativeCompilerReturnValue = results.NativeCompilerReturnValue;
results2.Errors.Add(error);
HttpCompileException compileException = new HttpCompileException(results2, assemblyBuilder.GetGeneratedSourceFromBuildProvider(buildProviderFromLinePragma));
BuildResult result = new BuildResultCompileError(buildProviderFromLinePragma.VirtualPathObject, compileException);
buildProviderFromLinePragma.SetBuildResultDependencies(result);
BuildManager.CacheVPathBuildResult(buildProviderFromLinePragma.VirtualPathObject, result, this._utcStart);
}
}
}
}
示例11: ProcessResults
private static void ProcessResults(CompilerResults results)
{
if (results.Errors.Count != 0)
throw new CompilingErrorsException(results.Errors.OfType<CompilerError>().ToArray());
if (results.CompiledAssembly == null)
throw new CompilingException(CouldNotLocateAssemblyErrorMessage);
}
示例12: Check
private static _Assembly Check(CompilerResults results) {
if (results.Errors.Count > 0) {
throw new CompilerException(results);
}
return results.CompiledAssembly;
}
示例13: BuildManagerCacheItem
public BuildManagerCacheItem (Assembly assembly, BuildProvider bp, CompilerResults results)
{
this.BuiltAssembly = assembly;
this.CompiledCustomString = bp.GetCustomString (results);
this.VirtualPath = bp.VirtualPath;
this.Type = bp.GetGeneratedType (results);
}
示例14: GetGeneratedType
public override Type GetGeneratedType(CompilerResults results)
{
if (this.xamlBuildProviderExtension != null)
{
Type result = this.xamlBuildProviderExtension.GetGeneratedType(results);
if (result != null)
{
return result;
}
}
try
{
XamlType rootXamlType = GetRootXamlType();
if (rootXamlType.IsUnknown)
{
StringBuilder typeName = new StringBuilder();
AppendTypeName(rootXamlType, typeName);
throw FxTrace.Exception.AsError(new TypeLoadException(SR.CouldNotResolveType(typeName)));
}
return rootXamlType.UnderlyingType;
}
catch (XamlParseException ex)
{
throw FxTrace.Exception.AsError(new HttpCompileException(ex.Message, ex));
}
}
示例15: CompileAssemblyFromSource
// Build an assembly from a list of source strings.
public override CompilerResults CompileAssemblyFromSource(CompilerParameters options, params string[] sources)
{
var root = new Root();
foreach(string code in sources)
parser.Parse(root, code);
if(root.CompilerErrors.Count > 0)
{
var results = new CompilerResults(null);
foreach(var e in root.CompilerErrors)
results.Errors.Add(e);
return results;
}
validator.Validate(options, root);
if (root.CompilerErrors.Count > 0)
{
var results = new CompilerResults(null);
foreach (var e in root.CompilerErrors)
results.Errors.Add(e);
return results;
}
var codeDomEmitter = new CodeDomEmitter();
return codeDomEmitter.Emit(options, root);
}