protected ExpressionContext CreateGenericContext(object owner) { ExpressionContext context; if (owner == null) { context = new ExpressionContext(); } else { context = new ExpressionContext(owner); } context.Options.OwnerMemberAccess = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic; context.Imports.ImportBuiltinTypes(); context.Imports.AddType(typeof(Math), "Math"); context.Imports.AddType(typeof(Uri), "Uri"); // context.Imports.AddType(typeof(Mouse), "Mouse"); context.Imports.AddType(typeof(Monitor), "Monitor"); context.Imports.AddType(typeof(DateTime), "DateTime"); context.Imports.AddType(typeof(Convert), "Convert"); context.Imports.AddType(typeof(Type), "Type"); context.Imports.AddType(typeof(DayOfWeek), "DayOfWeek"); context.Imports.AddType(typeof(ConsoleModifiers), "ConsoleModifiers"); var ns1 = new NamespaceImport("ns1"); var ns2 = new NamespaceImport("ns2"); ns2.Add(new TypeImport(typeof(Math))); ns1.Add(ns2); context.Imports.RootImport.Add(ns1); context.Variables.Add("varInt32", 100); context.Variables.Add("varDecimal", new decimal(100)); context.Variables.Add("varString", "string"); return(context); }
protected ExpressionContext CreateGenericContext(object owner) { var flag = owner == null; ExpressionContext context; if (flag) { context = new ExpressionContext(); } else { context = new ExpressionContext(RuntimeHelpers.GetObjectValue(owner)); } context.Options.OwnerMemberAccess = BindingFlags.Public | BindingFlags.NonPublic; context.Imports.ImportBuiltinTypes(); context.Imports.AddType(typeof(Math), "Math"); context.Imports.AddType(typeof(Uri), "Uri"); context.Imports.AddType(typeof(Mouse), "Mouse"); context.Imports.AddType(typeof(Monitor), "Monitor"); context.Imports.AddType(typeof(DateTime), "DateTime"); context.Imports.AddType(typeof(Convert), "Convert"); context.Imports.AddType(typeof(Type), "Type"); context.Imports.AddType(typeof(DayOfWeek), "DayOfWeek"); context.Imports.AddType(typeof(ConsoleModifiers), "ConsoleModifiers"); var ns = new NamespaceImport("ns1"); var ns2 = new NamespaceImport("ns2") { new TypeImport(typeof(Math)) }; ns.Add(ns2); context.Imports.RootImport.Add(ns); context.Variables.Add("varInt32", 100); context.Variables.Add("varDecimal", 100m); context.Variables.Add("varString", "string"); return(context); }