2 // eval.cs: Evaluation and Hosting API for the C# compiler
5 // Miguel de Icaza (miguel@gnome.org)
6 // Marek Safar (marek.safar@gmail.com)
8 // Dual licensed under the terms of the MIT X11 or GNU GPL
10 // Copyright 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
11 // Copyright 2004-2011 Novell, Inc
12 // Copyright 2011 Xamarin Inc
16 using System.Threading;
17 using System.Collections.Generic;
18 using System.Reflection;
19 using System.Reflection.Emit;
28 /// Evaluator: provides an API to evaluate C# statements and
29 /// expressions dynamically.
32 /// This class exposes static methods to evaluate expressions in the
35 /// To initialize the evaluator with a number of compiler
36 /// options call the Init(string[]args) method with a set of
37 /// command line options that the compiler recognizes.
39 /// To interrupt execution of a statement, you can invoke the
40 /// Evaluator.Interrupt method.
42 public class Evaluator {
45 // Parse silently, do not output any error messages
48 // Report errors during parse
51 // Auto-complete, means that the tokenizer will start producing
52 // GETCOMPLETIONS tokens when it reaches a certain point.
56 static object evaluator_lock = new object ();
57 static volatile bool invoking;
62 static Thread invoke_thread;
64 readonly Dictionary<string, Tuple<FieldSpec, FieldInfo>> fields;
70 readonly CompilerContext ctx;
71 readonly ModuleContainer module;
72 readonly ReflectionImporter importer;
73 readonly CompilationSourceFile source_file;
75 public Evaluator (CompilerContext ctx)
79 module = new ModuleContainer (ctx);
80 module.Evaluator = this;
82 source_file = new CompilationSourceFile (module, null);
83 module.AddTypeContainer (source_file);
85 startup_files = ctx.SourceFiles.Count;
87 // FIXME: Importer needs this assembly for internalsvisibleto
88 module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "evaluator"));
89 importer = new ReflectionImporter (module, ctx.BuiltinTypes);
91 InteractiveBaseClass = typeof (InteractiveBase);
92 fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
97 var loader = new DynamicLoader (importer, ctx);
99 CompilerCallableEntryPoint.Reset ();
100 RootContext.ToplevelTypes = module;
102 //var startup_files = new List<string> ();
103 //foreach (CompilationUnit file in Location.SourceFiles)
104 // startup_files.Add (file.Path);
106 loader.LoadReferences (module);
107 ctx.BuiltinTypes.CheckDefinitions (module);
108 module.InitializePredefinedTypes ();
113 void ParseStartupFiles ()
115 Driver d = new Driver (ctx);
117 Location.Initialize (ctx.SourceFiles);
119 var parser_session = new ParserSession ();
120 for (int i = 0; i < startup_files; ++i) {
121 var sf = ctx.SourceFiles [i];
122 d.Parse (sf, module, parser_session, ctx.Report);
128 CompilerCallableEntryPoint.PartialReset ();
131 Location.Initialize (ctx.SourceFiles);
135 /// If true, turns type expressions into valid expressions
136 /// and calls the describe method on it
138 public bool DescribeTypeExpressions;
141 /// Whether the evaluator will use terse syntax, and the semicolons at the end are optional
143 public bool Terse = true;
146 /// The base class for the classes that host the user generated code
150 /// This is the base class that will host the code
151 /// executed by the Evaluator. By default
152 /// this is the Mono.CSharp.InteractiveBase class
153 /// which is useful for interactive use.
155 /// By changing this property you can control the
156 /// base class and the static members that are
157 /// available to your evaluated code.
159 public Type InteractiveBaseClass {
166 if (value != null && typeof (InteractiveBase).IsAssignableFrom (value))
167 InteractiveBase.Evaluator = this;
172 /// Interrupts the evaluation of an expression executing in Evaluate.
175 /// Use this method to interrupt long-running invocations.
177 public void Interrupt ()
179 if (!inited || !invoking)
182 if (invoke_thread != null)
183 invoke_thread.Abort ();
187 /// Compiles the input string and returns a delegate that represents the compiled code.
191 /// Compiles the input string as a C# expression or
192 /// statement, unlike the Evaluate method, the
193 /// resulting delegate can be invoked multiple times
194 /// without incurring in the compilation overhead.
196 /// If the return value of this function is null,
197 /// this indicates that the parsing was complete.
198 /// If the return value is a string it indicates
199 /// that the input string was partial and that the
200 /// invoking code should provide more code before
201 /// the code can be successfully compiled.
203 /// If you know that you will always get full expressions or
204 /// statements and do not care about partial input, you can use
205 /// the other Compile overload.
207 /// On success, in addition to returning null, the
208 /// compiled parameter will be set to the delegate
209 /// that can be invoked to execute the code.
212 public string Compile (string input, out CompiledMethod compiled)
214 if (input == null || input.Length == 0){
219 lock (evaluator_lock){
222 ParseStartupFiles ();
224 ctx.Report.Printer.Reset ();
228 CSharpParser parser = ParseString (ParseMode.Silent, input, out partial_input);
230 // Terse mode, try to provide the trailing semicolon automatically.
231 if (parser == null && Terse && partial_input){
234 // check if the source would compile with a block, if so, we should not
235 // add the semicolon.
236 var needs_block = ParseString (ParseMode.Silent, input + "{}", out ignore) != null;
238 parser = ParseString (ParseMode.Silent, input + ";", out ignore);
245 ParseString (ParseMode.ReportErrors, input, out partial_input);
249 Class parser_result = parser.InteractiveResult;
250 compiled = CompileBlock (parser_result, parser.undo, ctx.Report);
256 /// Compiles the input string and returns a delegate that represents the compiled code.
260 /// Compiles the input string as a C# expression or
261 /// statement, unlike the Evaluate method, the
262 /// resulting delegate can be invoked multiple times
263 /// without incurring in the compilation overhead.
265 /// This method can only deal with fully formed input
266 /// strings and does not provide a completion mechanism.
267 /// If you must deal with partial input (for example for
268 /// interactive use) use the other overload.
270 /// On success, a delegate is returned that can be used
271 /// to invoke the method.
274 public CompiledMethod Compile (string input)
276 CompiledMethod compiled;
278 // Ignore partial inputs
279 if (Compile (input, out compiled) != null){
280 // Error, the input was partial.
284 // Either null (on error) or the compiled method.
289 /// Evaluates and expression or statement and returns any result values.
292 /// Evaluates the input string as a C# expression or
293 /// statement. If the input string is an expression
294 /// the result will be stored in the result variable
295 /// and the result_set variable will be set to true.
297 /// It is necessary to use the result/result_set
298 /// pair to identify when a result was set (for
299 /// example, execution of user-provided input can be
300 /// an expression, a statement or others, and
301 /// result_set would only be set if the input was an
304 /// If the return value of this function is null,
305 /// this indicates that the parsing was complete.
306 /// If the return value is a string, it indicates
307 /// that the input is partial and that the user
308 /// should provide an updated string.
310 public string Evaluate (string input, out object result, out bool result_set)
312 CompiledMethod compiled;
317 input = Compile (input, out compiled);
321 if (compiled == null)
325 // The code execution does not need to keep the compiler lock
327 object retval = typeof (QuitValue);
330 invoke_thread = System.Threading.Thread.CurrentThread;
332 compiled (ref retval);
333 } catch (ThreadAbortException e){
334 Thread.ResetAbort ();
335 Console.WriteLine ("Interrupted!\n{0}", e);
341 // We use a reference to a compiler type, in this case
342 // Driver as a flag to indicate that this was a statement
344 if (!ReferenceEquals (retval, typeof (QuitValue))) {
352 public string [] GetCompletions (string input, out string prefix)
355 if (input == null || input.Length == 0)
358 lock (evaluator_lock){
363 CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
368 Class parser_result = parser.InteractiveResult;
371 var access = AssemblyBuilderAccess.RunAndCollect;
373 var access = AssemblyBuilderAccess.Run;
375 var a = new AssemblyDefinitionDynamic (module, "completions");
376 a.Create (AppDomain.CurrentDomain, access);
377 module.SetDeclaringAssembly (a);
379 // Need to setup MemberCache
380 parser_result.CreateContainer ();
382 var method = parser_result.Members[0] as Method;
383 BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
386 method.Block.Resolve (null, bc, method);
387 } catch (CompletionResult cr) {
388 prefix = cr.BaseText;
396 /// Executes the given expression or statement.
399 /// Executes the provided statement, returns true
400 /// on success, false on parsing errors. Exceptions
401 /// might be thrown by the called code.
403 public bool Run (string statement)
408 return Evaluate (statement, out result, out result_set) == null;
412 /// Evaluates and expression or statement and returns the result.
415 /// Evaluates the input string as a C# expression or
416 /// statement and returns the value.
418 /// This method will throw an exception if there is a syntax error,
419 /// of if the provided input is not an expression but a statement.
421 public object Evaluate (string input)
426 string r = Evaluate (input, out result, out result_set);
429 throw new ArgumentException ("Syntax error on input: partial input");
431 if (result_set == false)
432 throw new ArgumentException ("The expression did not set a result");
439 StatementOrExpression,
445 // Deambiguates the input string to determine if we
446 // want to process a statement or if we want to
447 // process a compilation unit.
449 // This is done using a top-down predictive parser,
450 // since the yacc/jay parser can not deambiguage this
451 // without more than one lookahead token. There are very
454 InputKind ToplevelOrStatement (SeekableStreamReader seekable)
456 Tokenizer tokenizer = new Tokenizer (seekable, source_file, new ParserSession ());
458 // Prefer contextual block keywords over identifiers
459 tokenizer.parsing_block++;
461 int t = tokenizer.token ();
464 return InputKind.EOF;
466 // These are toplevels
468 case Token.OPEN_BRACKET:
472 case Token.INTERFACE:
474 case Token.NAMESPACE:
476 case Token.PROTECTED:
481 return InputKind.CompilationUnit;
483 // Definitely expression
500 return InputKind.StatementOrExpression;
502 // These need deambiguation help
504 t = tokenizer.token ();
506 return InputKind.EOF;
508 if (t == Token.IDENTIFIER)
509 return InputKind.CompilationUnit;
510 return InputKind.StatementOrExpression;
513 // Distinguish between:
514 // delegate opt_anonymous_method_signature block
517 t = tokenizer.token ();
519 return InputKind.EOF;
520 if (t == Token.OPEN_PARENS || t == Token.OPEN_BRACE)
521 return InputKind.StatementOrExpression;
522 return InputKind.CompilationUnit;
524 // Distinguih between:
526 // unsafe as modifier of a type declaration
528 t = tokenizer.token ();
530 return InputKind.EOF;
531 if (t == Token.OPEN_PARENS)
532 return InputKind.StatementOrExpression;
533 return InputKind.CompilationUnit;
535 // These are errors: we list explicitly what we had
536 // from the grammar, ERROR and then everything else
541 return InputKind.Error;
543 // This catches everything else allowed by
544 // expressions. We could add one-by-one use cases
547 return InputKind.StatementOrExpression;
552 // Parses the string @input and returns a CSharpParser if succeeful.
554 // if @silent is set to true then no errors are
555 // reported to the user. This is used to do various calls to the
556 // parser and check if the expression is parsable.
558 // @partial_input: if @silent is true, then it returns whether the
559 // parsed expression was partial, and more data is needed
561 CSharpParser ParseString (ParseMode mode, string input, out bool partial_input)
563 partial_input = false;
566 var enc = ctx.Settings.Encoding;
567 var s = new MemoryStream (enc.GetBytes (input));
568 SeekableStreamReader seekable = new SeekableStreamReader (s, enc);
570 InputKind kind = ToplevelOrStatement (seekable);
571 if (kind == InputKind.Error){
572 if (mode == ParseMode.ReportErrors)
573 ctx.Report.Error (-25, "Detection Parsing Error");
574 partial_input = false;
578 if (kind == InputKind.EOF){
579 if (mode == ParseMode.ReportErrors)
580 Console.Error.WriteLine ("Internal error: EOF condition should have been detected in a previous call with silent=true");
581 partial_input = true;
585 seekable.Position = 0;
587 source_file.DeclarationFound = false;
588 CSharpParser parser = new CSharpParser (seekable, source_file, new ParserSession ());
590 if (kind == InputKind.StatementOrExpression){
591 parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
592 parser.Lexer.parsing_block++;
593 ctx.Settings.StatementMode = true;
595 parser.Lexer.putback_char = Tokenizer.EvalCompilationUnitParserCharacter;
596 ctx.Settings.StatementMode = false;
599 if (mode == ParseMode.GetCompletions)
600 parser.Lexer.CompleteOnEOF = true;
602 ReportPrinter old_printer = null;
603 if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions))
604 old_printer = ctx.Report.SetPrinter (new StreamReportPrinter (TextWriter.Null));
609 if (ctx.Report.Errors != 0){
610 if (mode != ParseMode.ReportErrors && parser.UnexpectedEOF)
611 partial_input = true;
613 if (parser.undo != null)
614 parser.undo.ExecuteUndo ();
619 if (old_printer != null)
620 ctx.Report.SetPrinter (old_printer);
625 CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
628 throw new NotSupportedException ();
630 string current_debug_name = "eval-" + count + ".dll";
633 AssemblyDefinitionDynamic assembly;
634 AssemblyBuilderAccess access;
636 if (Environment.GetEnvironmentVariable ("SAVE") != null) {
637 access = AssemblyBuilderAccess.RunAndSave;
638 assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
639 assembly.Importer = importer;
642 access = AssemblyBuilderAccess.RunAndCollect;
644 access = AssemblyBuilderAccess.Run;
646 assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
649 assembly.Create (AppDomain.CurrentDomain, access);
651 Method expression_method;
653 var base_class_imported = importer.ImportType (base_class);
654 var baseclass_list = new List<FullNamedExpression> (1) {
655 new TypeExpression (base_class_imported, host.Location)
658 host.AddBasesForPart (baseclass_list);
660 host.CreateContainer ();
661 host.DefineContainer ();
664 expression_method = (Method) host.Members[0];
666 expression_method = null;
669 module.CreateContainer ();
671 // Disable module and source file re-definition checks
672 module.EnableRedefinition ();
673 source_file.EnableRedefinition ();
677 if (Report.Errors != 0){
685 host.EmitContainer ();
688 module.EmitContainer ();
689 if (Report.Errors != 0){
695 module.CloseContainer ();
697 host.CloseContainer ();
699 if (access == AssemblyBuilderAccess.RunAndSave)
706 // Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
707 // work from MethodBuilders. Retarded, I know.
709 var tt = assembly.Builder.GetType (host.TypeBuilder.Name);
710 var mi = tt.GetMethod (expression_method.MemberName.Name);
713 // We need to then go from FieldBuilder to FieldInfo
714 // or reflection gets confused (it basically gets confused, and variables override each
717 foreach (var member in host.Members) {
718 var field = member as Field;
722 var fi = tt.GetField (field.Name);
724 Tuple<FieldSpec, FieldInfo> old;
726 // If a previous value was set, nullify it, so that we do
728 if (fields.TryGetValue (field.Name, out old)) {
729 if (old.Item1.MemberType.IsStruct) {
731 // TODO: Clear fields for structs
735 old.Item2.SetValue (null, null);
741 fields[field.Name] = Tuple.Create (field.Spec, fi);
744 return (CompiledMethod) System.Delegate.CreateDelegate (typeof (CompiledMethod), mi);
749 /// A sentinel value used to indicate that no value was
750 /// was set by the compiled function. This is used to
751 /// differentiate between a function not returning a
754 internal static class QuitValue { }
756 internal Tuple<FieldSpec, FieldInfo> LookupField (string name)
758 Tuple<FieldSpec, FieldInfo> fi;
759 fields.TryGetValue (name, out fi);
763 static string Quote (string s)
765 if (s.IndexOf ('"') != -1)
766 s = s.Replace ("\"", "\\\"");
768 return "\"" + s + "\"";
771 public string GetUsing ()
773 StringBuilder sb = new StringBuilder ();
775 //foreach (object x in ns.using_alias_list)
776 // sb.AppendFormat ("using {0};\n", x);
778 foreach (var ue in source_file.Usings) {
779 sb.AppendFormat ("using {0};", ue.ToString ());
780 sb.Append (Environment.NewLine);
783 return sb.ToString ();
786 internal List<string> GetUsingList ()
788 var res = new List<string> ();
790 foreach (var ue in source_file.Usings) {
791 if (ue.Alias != null || ue.ResolvedExpression == null)
794 res.Add (ue.NamespaceExpression.Name);
800 internal string [] GetVarNames ()
802 lock (evaluator_lock){
803 return new List<string> (fields.Keys).ToArray ();
807 public string GetVars ()
809 lock (evaluator_lock){
810 StringBuilder sb = new StringBuilder ();
812 foreach (var de in fields){
813 var fi = LookupField (de.Key);
816 value = fi.Item2.GetValue (null);
818 value = Quote ((string)value);
820 value = "<error reading value>";
823 sb.AppendFormat ("{0} {1} = {2}", fi.Item1.MemberType.GetSignatureForError (), de.Key, value);
827 return sb.ToString ();
832 /// Loads the given assembly and exposes the API to the user.
834 public void LoadAssembly (string file)
836 var loader = new DynamicLoader (importer, ctx);
837 var assembly = loader.LoadAssemblyFile (file, false);
838 if (assembly == null)
841 lock (evaluator_lock){
842 importer.ImportAssembly (assembly, module.GlobalRootNamespace);
847 /// Exposes the API of the given assembly to the Evaluator
849 public void ReferenceAssembly (Assembly a)
851 lock (evaluator_lock){
852 importer.ImportAssembly (a, module.GlobalRootNamespace);
859 /// A delegate that can be used to invoke the
860 /// compiled expression or statement.
863 /// Since the Compile methods will compile
864 /// statements and expressions into the same
865 /// delegate, you can tell if a value was returned
866 /// by checking whether the returned value is of type
870 public delegate void CompiledMethod (ref object retvalue);
873 /// The default base class for every interaction line
876 /// The expressions and statements behave as if they were
877 /// a static method of this class. The InteractiveBase class
878 /// contains a number of useful methods, but can be overwritten
879 /// by setting the InteractiveBaseType property in the Evaluator
881 public class InteractiveBase {
883 /// Determines where the standard output of methods in this class will go.
885 public static TextWriter Output = Console.Out;
888 /// Determines where the standard error of methods in this class will go.
890 public static TextWriter Error = Console.Error;
893 /// The primary prompt used for interactive use.
895 public static string Prompt = "csharp> ";
898 /// The secondary prompt used for interactive use (used when
899 /// an expression is incomplete).
901 public static string ContinuationPrompt = " > ";
904 /// Used to signal that the user has invoked the `quit' statement.
906 public static bool QuitRequested;
908 public static Evaluator Evaluator;
911 /// Shows all the variables defined so far.
913 static public void ShowVars ()
915 Output.Write (Evaluator.GetVars ());
920 /// Displays the using statements in effect at this point.
922 static public void ShowUsing ()
924 Output.Write (Evaluator.GetUsing ());
929 /// Times the execution of the given delegate
931 static public TimeSpan Time (Action a)
933 DateTime start = DateTime.Now;
935 return DateTime.Now - start;
939 /// Loads the assemblies from a package
942 /// Loads the assemblies from a package. This is equivalent
943 /// to passing the -pkg: command line flag to the C# compiler
944 /// on the command line.
946 static public void LoadPackage (string pkg)
949 Error.WriteLine ("Invalid package specified");
953 string pkgout = Driver.GetPackageFlags (pkg, null);
955 string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
956 Split (new Char [] { ' ', '\t'});
958 foreach (string s in xargs){
959 if (s.StartsWith ("-r:") || s.StartsWith ("/r:") || s.StartsWith ("/reference:")){
960 string lib = s.Substring (s.IndexOf (':')+1);
962 Evaluator.LoadAssembly (lib);
969 /// Loads the assembly
972 /// Loads the specified assembly and makes its types
973 /// available to the evaluator. This is equivalent
974 /// to passing the -pkg: command line flag to the C#
975 /// compiler on the command line.
977 static public void LoadAssembly (string assembly)
979 Evaluator.LoadAssembly (assembly);
982 static public void print (object obj)
984 Output.WriteLine (obj);
987 static public void print (string fmt, params object [] args)
989 Output.WriteLine (fmt, args);
993 /// Returns a list of available static methods.
995 static public string help {
997 return "Static methods:\n" +
999 " Describe (object); - Describes the object's type\n" +
1001 " LoadPackage (package); - Loads the given Package (like -pkg:FILE)\n" +
1002 " LoadAssembly (assembly); - Loads the given assembly (like -r:ASSEMBLY)\n" +
1003 " ShowVars (); - Shows defined local variables.\n" +
1004 " ShowUsing (); - Show active using declarations.\n" +
1005 " Prompt - The prompt used by the C# shell\n" +
1006 " ContinuationPrompt - The prompt for partial input\n" +
1007 " Time (() => { }); - Times the specified code\n" +
1008 " print (obj); - Shorthand for Console.WriteLine\n" +
1009 " quit; - You'll never believe it - this quits the repl!\n" +
1010 " help; - This help text\n";
1015 /// Indicates to the read-eval-print-loop that the interaction should be finished.
1017 static public object quit {
1019 QuitRequested = true;
1021 // To avoid print null at the exit
1022 return typeof (Evaluator.QuitValue);
1027 /// Same as quit - useful in script scenerios
1029 static public void Quit () {
1030 QuitRequested = true;
1035 /// Describes an object or a type.
1038 /// This method will show a textual representation
1039 /// of the object's type. If the object is a
1040 /// System.Type it renders the type directly,
1041 /// otherwise it renders the type returned by
1042 /// invoking GetType on the object.
1044 static public string Describe (object x)
1049 var type = x as Type ?? x.GetType ();
1051 StringWriter sw = new StringWriter ();
1052 new Outline (type, sw, true, false, false).OutlineType ();
1053 return sw.ToString ();
1058 class HoistedEvaluatorVariable : HoistedVariable
1060 public HoistedEvaluatorVariable (Field field)
1061 : base (null, field)
1065 protected override FieldExpr GetFieldExpression (EmitContext ec)
1067 return new FieldExpr (field, field.Location);
1072 /// A class used to assign values if the source expression is not void
1074 /// Used by the interactive shell to allow it to call this code to set
1075 /// the return value for an invocation.
1077 class OptionalAssign : SimpleAssign {
1078 public OptionalAssign (Expression t, Expression s, Location loc)
1083 protected override Expression DoResolve (ResolveContext ec)
1085 Expression clone = source.Clone (new CloneContext ());
1087 clone = clone.Resolve (ec);
1092 // A useful feature for the REPL: if we can resolve the expression
1093 // as a type, Describe the type;
1095 if (ec.Module.Evaluator.DescribeTypeExpressions){
1096 var old_printer = ec.Report.SetPrinter (new SessionReportPrinter ());
1099 // Note: clone context cannot be shared otherwise block mapping would leak
1100 tclone = source.Clone (new CloneContext ());
1101 tclone = tclone.Resolve (ec, ResolveFlags.Type);
1102 if (ec.Report.Errors > 0)
1105 ec.Report.SetPrinter (old_printer);
1108 if (tclone is TypeExpr) {
1109 Arguments args = new Arguments (1);
1110 args.Add (new Argument (new TypeOf ((TypeExpr) clone, Location)));
1111 return new Invocation (new SimpleName ("Describe", Location), args).Resolve (ec);
1115 // This means its really a statement.
1116 if (clone.Type.Kind == MemberKind.Void || clone is DynamicInvocation || clone is Assign) {
1121 return base.DoResolve (ec);
1127 List<Action> undo_actions;
1133 public void AddTypeContainer (TypeContainer current_container, TypeDefinition tc)
1135 if (current_container == tc){
1136 Console.Error.WriteLine ("Internal error: inserting container into itself");
1140 if (undo_actions == null)
1141 undo_actions = new List<Action> ();
1143 var existing = current_container.Containers.FirstOrDefault (l => l.Basename == tc.Basename);
1144 if (existing != null) {
1145 current_container.RemoveContainer (existing);
1146 undo_actions.Add (() => current_container.AddTypeContainer (existing));
1149 undo_actions.Add (() => current_container.RemoveContainer (tc));
1152 public void ExecuteUndo ()
1154 if (undo_actions == null)
1157 foreach (var p in undo_actions){
1161 undo_actions = null;