本文整理汇总了C#中AssemblyDefinitionDynamic类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyDefinitionDynamic类的具体用法?C# AssemblyDefinitionDynamic怎么用?C# AssemblyDefinitionDynamic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyDefinitionDynamic类属于命名空间,在下文中一共展示了AssemblyDefinitionDynamic类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CompileBlock
CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
{
#if STATIC
throw new NotSupportedException ();
#else
string current_debug_name = "eval-" + count + ".dll";
++count;
AssemblyDefinitionDynamic assembly;
AssemblyBuilderAccess access;
if (Environment.GetEnvironmentVariable ("SAVE") != null) {
access = AssemblyBuilderAccess.RunAndSave;
assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
assembly.Importer = importer;
} else {
#if NET_4_0
access = AssemblyBuilderAccess.RunAndCollect;
#else
access = AssemblyBuilderAccess.Run;
#endif
assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
}
assembly.Create (AppDomain.CurrentDomain, access);
Method expression_method;
if (host != null) {
var base_class_imported = importer.ImportType (base_class);
var baseclass_list = new List<FullNamedExpression> (1) {
new TypeExpression (base_class_imported, host.Location)
};
host.AddBasesForPart (baseclass_list);
host.CreateContainer ();
host.DefineContainer ();
host.Define ();
expression_method = (Method) host.Members[0];
} else {
expression_method = null;
}
module.CreateContainer ();
source_file.EnableUsingClausesRedefinition ();
module.Define ();
if (Report.Errors != 0){
if (undo != null)
undo.ExecuteUndo ();
return null;
}
if (host != null){
host.EmitContainer ();
}
module.EmitContainer ();
if (Report.Errors != 0){
if (undo != null)
undo.ExecuteUndo ();
return null;
}
module.CloseContainer ();
if (host != null)
host.CloseContainer ();
if (access == AssemblyBuilderAccess.RunAndSave)
assembly.Save ();
if (host == null)
return null;
//
// Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
// work from MethodBuilders. Retarded, I know.
//
var tt = assembly.Builder.GetType (host.TypeBuilder.Name);
var mi = tt.GetMethod (expression_method.MemberName.Name);
//
// We need to then go from FieldBuilder to FieldInfo
// or reflection gets confused (it basically gets confused, and variables override each
// other).
//
foreach (var member in host.Members) {
var field = member as Field;
if (field == null)
continue;
var fi = tt.GetField (field.Name);
Tuple<FieldSpec, FieldInfo> old;
// If a previous value was set, nullify it, so that we do
// not leak memory
if (fields.TryGetValue (field.Name, out old)) {
//.........这里部分代码省略.........
开发者ID:KAW0,项目名称:Alter-Native,代码行数:101,代码来源:eval.cs
示例2: CompileBlock
CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
{
#if STATIC
throw new NotSupportedException ();
#else
string current_debug_name = "eval-" + count + ".dll";
++count;
AssemblyDefinitionDynamic assembly;
AssemblyBuilderAccess access;
if (Environment.GetEnvironmentVariable ("SAVE") != null) {
access = AssemblyBuilderAccess.RunAndSave;
assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
assembly.Importer = importer;
} else {
#if NET_4_0
access = AssemblyBuilderAccess.RunAndCollect;
#else
access = AssemblyBuilderAccess.Run;
#endif
assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
}
assembly.Create (AppDomain.CurrentDomain, access);
Method expression_method;
if (host != null) {
var base_class_imported = importer.ImportType (base_class);
var baseclass_list = new List<FullNamedExpression> (1) {
new TypeExpression (base_class_imported, host.Location)
};
host.SetBaseTypes (baseclass_list);
expression_method = (Method) host.Members[0];
if ((expression_method.ModFlags & Modifiers.ASYNC) != 0) {
//
// Host method is async. When WaitOnTask is set we wrap it with wait
//
// void AsyncWait (ref object $retval) {
// $retval = Host();
// ((Task)$retval).Wait(); // When WaitOnTask is set
// }
//
var p = new ParametersCompiled (
new Parameter (new TypeExpression (module.Compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null)
);
var method = new Method(host, new TypeExpression(module.Compiler.BuiltinTypes.Void, Location.Null),
Modifiers.PUBLIC | Modifiers.STATIC, new MemberName("AsyncWait"), p, null);
method.Block = new ToplevelBlock(method.Compiler, p, Location.Null);
method.Block.AddStatement(new StatementExpression (new SimpleAssign(
new SimpleName(p [0].Name, Location.Null),
new Invocation(new SimpleName(expression_method.MemberName.Name, Location.Null), new Arguments(0)),
Location.Null), Location.Null));
if (WaitOnTask) {
var task = new Cast (expression_method.TypeExpression, new SimpleName (p [0].Name, Location.Null), Location.Null);
method.Block.AddStatement (new StatementExpression (new Invocation (
new MemberAccess (task, "Wait", Location.Null),
new Arguments (0)), Location.Null));
}
host.AddMember(method);
expression_method = method;
}
host.CreateContainer();
host.DefineContainer();
host.Define();
} else {
expression_method = null;
}
module.CreateContainer ();
// Disable module and source file re-definition checks
module.EnableRedefinition ();
source_file.EnableRedefinition ();
module.Define ();
if (Report.Errors != 0){
if (undo != null)
undo.ExecuteUndo ();
return null;
}
if (host != null){
host.PrepareEmit ();
host.EmitContainer ();
}
//.........这里部分代码省略.........
开发者ID:FrancisVarga,项目名称:mono,代码行数:101,代码来源:eval.cs
示例3: GetCompletions
public string [] GetCompletions (string input, out string prefix)
{
prefix = "";
if (input == null || input.Length == 0)
return null;
lock (evaluator_lock){
if (!inited)
Init ();
bool partial_input;
CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
if (parser == null){
return null;
}
Class parser_result = parser.InteractiveResult;
#if NET_4_0
var access = AssemblyBuilderAccess.RunAndCollect;
#else
var access = AssemblyBuilderAccess.Run;
#endif
var a = new AssemblyDefinitionDynamic (module, "completions");
a.Create (AppDomain.CurrentDomain, access);
module.SetDeclaringAssembly (a);
// Need to setup MemberCache
parser_result.CreateContainer ();
var method = parser_result.Members[0] as Method;
BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
try {
method.Block.Resolve (null, bc, method);
} catch (CompletionResult cr) {
prefix = cr.BaseText;
return cr.Result;
}
}
return null;
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:42,代码来源:eval.cs
示例4: GetCompletions
public static string [] GetCompletions (string input, out string prefix)
{
prefix = "";
if (input == null || input.Length == 0)
return null;
lock (evaluator_lock){
if (!inited)
Init ();
bool partial_input;
CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
if (parser == null){
if (CSharpParser.yacc_verbose_flag != 0)
Console.WriteLine ("DEBUG: No completions available");
return null;
}
Class parser_result = parser.InteractiveResult;
try {
var a = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp");
a.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run);
RootContext.ToplevelTypes.SetDeclaringAssembly (a);
RootContext.ToplevelTypes.CreateType ();
RootContext.ToplevelTypes.Define ();
parser_result.CreateType ();
parser_result.Define ();
if (ctx.Report.Errors != 0)
return null;
MethodOrOperator method = null;
foreach (MemberCore member in parser_result.Methods){
if (member.Name != "Host")
continue;
method = (MethodOrOperator) member;
break;
}
if (method == null)
throw new InternalErrorException ("did not find the the Host method");
BlockContext bc = new BlockContext (method, method.Block, method.ReturnType);
try {
method.Block.Resolve (null, bc, method);
} catch (CompletionResult cr){
prefix = cr.BaseText;
return cr.Result;
}
} finally {
parser.undo.ExecuteUndo ();
}
}
return null;
}
开发者ID:keith512,项目名称:mono,代码行数:58,代码来源:eval.cs
示例5: CompileBlock
static CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
{
AssemblyDefinitionDynamic assembly;
AssemblyBuilderAccess access;
if (Environment.GetEnvironmentVariable ("SAVE") != null) {
access = AssemblyBuilderAccess.RunAndSave;
assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name, current_debug_name);
assembly.Importer = loader.Importer;
} else {
#if NET_4_0
access = AssemblyBuilderAccess.RunAndCollect;
#else
access = AssemblyBuilderAccess.Run;
#endif
assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name);
}
assembly.Create (AppDomain.CurrentDomain, access);
if (host != null) {
host.CreateType ();
host.Define ();
}
RootContext.ToplevelTypes.CreateType ();
RootContext.ToplevelTypes.Define ();
if (Report.Errors != 0){
undo.ExecuteUndo ();
return null;
}
TypeBuilder tb = null;
MethodBuilder mb = null;
if (host != null){
tb = host.TypeBuilder;
mb = null;
foreach (MemberCore member in host.Methods){
if (member.Name != "Host")
continue;
MethodOrOperator method = (MethodOrOperator) member;
mb = method.MethodBuilder;
break;
}
if (mb == null)
throw new Exception ("Internal error: did not find the method builder for the generated method");
host.EmitType ();
}
RootContext.ToplevelTypes.Emit ();
if (Report.Errors != 0){
undo.ExecuteUndo ();
return null;
}
RootContext.ToplevelTypes.CloseType ();
if (host != null)
host.CloseType ();
if (access == AssemblyBuilderAccess.RunAndSave)
assembly.Save ();
if (host == null)
return null;
//
// Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
// work from MethodBuilders. Retarded, I know.
//
var tt = assembly.Builder.GetType (tb.Name);
MethodInfo mi = tt.GetMethod (mb.Name);
// Pull the FieldInfos from the type, and keep track of them
foreach (Field field in queued_fields){
FieldInfo fi = tt.GetField (field.Name);
Tuple<FieldSpec, FieldInfo> old;
// If a previous value was set, nullify it, so that we do
// not leak memory
if (fields.TryGetValue (field.Name, out old)) {
if (old.Item1.MemberType.IsStruct) {
//
// TODO: Clear fields for structs
//
} else {
try {
old.Item2.SetValue (null, null);
} catch {
}
}
fields [field.Name] = Tuple.Create (field.Spec, fi);
} else {
fields.Add (field.Name, Tuple.Create (field.Spec, fi));
//.........这里部分代码省略.........
开发者ID:keith512,项目名称:mono,代码行数:101,代码来源:eval.cs
示例6: Compile
//.........这里部分代码省略.........
output_file = output_file_name;
} else {
output_file_name = Path.GetFileName (output_file);
}
#if STATIC
var importer = new StaticImporter (module);
var references_loader = new StaticLoader (importer, ctx);
tr.Start (TimeReporter.TimerType.AssemblyBuilderSetup);
var assembly = new AssemblyDefinitionStatic (module, references_loader, output_file_name, output_file);
assembly.Create (references_loader.Domain);
tr.Stop (TimeReporter.TimerType.AssemblyBuilderSetup);
// Create compiler types first even before any referenced
// assembly is loaded to allow forward referenced types from
// loaded assembly into compiled builder to be resolved
// correctly
tr.Start (TimeReporter.TimerType.CreateTypeTotal);
module.CreateType ();
importer.AddCompiledAssembly (assembly);
tr.Stop (TimeReporter.TimerType.CreateTypeTotal);
references_loader.LoadReferences (module);
tr.Start (TimeReporter.TimerType.PredefinedTypesInit);
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
tr.Stop (TimeReporter.TimerType.PredefinedTypesInit);
references_loader.LoadModules (assembly, module.GlobalRootNamespace);
#else
var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
module.SetDeclaringAssembly (assembly);
var importer = new ReflectionImporter (module, ctx.BuildinTypes);
assembly.Importer = importer;
var loader = new DynamicLoader (importer, ctx);
loader.LoadReferences (module);
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run))
return false;
module.CreateType ();
loader.LoadModules (assembly, module.GlobalRootNamespace);
#endif
tr.Start (TimeReporter.TimerType.ModuleDefinitionTotal);
module.Define ();
tr.Stop (TimeReporter.TimerType.ModuleDefinitionTotal);
if (Report.Errors > 0)
return false;
//if (settings.Documentation != null &&
// !settings.Documentation.OutputDocComment (
// output_file, Report))
// return false;
//
// Verify using aliases now
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:67,代码来源:driver.cs
示例7: Compile
//
// Main compilation method
//
public bool Compile ()
{
var module = new ModuleContainer (ctx);
RootContext.ToplevelTypes = module;
if (timestamps) {
stopwatch = Stopwatch.StartNew ();
first_time = DateTime.Now;
}
Parse (module);
ShowTime ("Parsing source files");
if (Report.Errors > 0)
return false;
if (RootContext.TokenizeOnly || RootContext.ParseOnly)
return true;
if (RootContext.ToplevelTypes.NamespaceEntry != null)
throw new InternalErrorException ("who set it?");
//
// Quick hack
//
var output_file = RootContext.OutputFile;
string output_file_name;
if (output_file == null) {
if (first_source == null) {
Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
return false;
}
int pos = first_source.LastIndexOf ('.');
if (pos > 0)
output_file = first_source.Substring (0, pos) + RootContext.TargetExt;
else
output_file = first_source + RootContext.TargetExt;
output_file_name = output_file;
} else {
output_file_name = Path.GetFileName (output_file);
}
//
// Load assemblies required
//
if (timestamps)
stopwatch = Stopwatch.StartNew ();
#if STATIC
var assembly = new AssemblyDefinitionStatic (module, output_file_name, output_file);
module.SetDeclaringAssembly (assembly);
var importer = new StaticImporter ();
assembly.Importer = importer;
var loader = new StaticLoader (importer, ctx);
loader.LoadReferences (module);
ShowTime ("Imporing referenced assemblies");
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
ShowTime ("Initializing predefined types");
if (!assembly.Create (loader))
return false;
// System.Object was not loaded, use compiled assembly as corlib
if (loader.Corlib == null)
loader.Corlib = assembly.Builder;
loader.LoadModules (assembly, module.GlobalRootNamespace);
#else
var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
module.SetDeclaringAssembly (assembly);
var importer = new ReflectionImporter (ctx.BuildinTypes);
assembly.Importer = importer;
var loader = new DynamicLoader (importer, ctx);
loader.LoadReferences (module);
ShowTime ("Imporing referenced assemblies");
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
ShowTime ("Initializing predefined types");
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
return false;
loader.LoadModules (assembly, module.GlobalRootNamespace);
//.........这里部分代码省略.........
开发者ID:litoMalone,项目名称:mono,代码行数:101,代码来源:driver.cs
示例8: GetCompletions
public string[] GetCompletions(string input, out string prefix)
{
prefix = "";
if (input == null || input.Length == 0)
return null;
try
{
invoke_thread = System.Threading.Thread.CurrentThread;
invoking = true;
lock (evaluator_lock)
{
if (!inited)
Init();
bool partial_input;
CSharpParser parser = ParseString(ParseMode.GetCompletions, input, out partial_input);
if (parser == null)
{
if (CSharpParser.yacc_verbose_flag != 0)
Console.WriteLine("DEBUG: No completions available");
return null;
}
Class parser_result = parser.InteractiveResult;
#if NET_4_0
var access = AssemblyBuilderAccess.Run;
#else
var access = AssemblyBuilderAccess.Run;
#endif
var a = new AssemblyDefinitionDynamic(module, "completions");
a.Create(AppDomain.CurrentDomain, access);
module.SetDeclaringAssembly(a);
// Need to setup MemberCache
parser_result.CreateType();
var method = parser_result.Methods[0] as Method;
BlockContext bc = new BlockContext(method, method.Block, TypeManager.void_type);
try
{
method.Block.Resolve(null, bc, method);
}
catch (CompletionResult cr)
{
prefix = cr.BaseText;
return cr.Result;
}
}
}
catch (ThreadAbortException e)
{
Console.WriteLine("Interrupted!\n{0}", e);
}
finally
{
invoking = false;
}
return null;
}
开发者ID:jorik041,项目名称:runcs,代码行数:64,代码来源:eval.cs
示例9: GetCompletions
public string [] GetCompletions (string input, out string prefix)
{
prefix = "";
if (input == null || input.Length == 0)
return null;
lock (evaluator_lock){
if (!inited)
Init ();
bool partial_input;
CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
if (parser == null){
return null;
}
Class host = parser.InteractiveResult;
var base_class_imported = importer.ImportType (base_class);
var baseclass_list = new List<FullNamedExpression> (1) {
new TypeExpression (base_class_imported, host.Location)
};
host.SetBaseTypes (baseclass_list);
var access = AssemblyBuilderAccess.RunAndCollect;
var a = new AssemblyDefinitionDynamic (module, "completions");
a.Create (AppDomain.CurrentDomain, access);
module.SetDeclaringAssembly (a);
// Need to setup MemberCache
host.CreateContainer ();
// Need to setup base type
host.DefineContainer ();
var method = host.Members[0] as Method;
BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
try {
method.Block.Resolve (bc, method);
} catch (CompletionResult cr) {
prefix = cr.BaseText;
return cr.Result;
}
}
return null;
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:46,代码来源:eval.cs
注:本文中的AssemblyDefinitionDynamic类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论