Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            _func = null;

            var compiler = new FormulaCompiler();

            if (Custom.IsChecked ?? false)
            {
                compiler.
                WithMethod("rand", () => new Random(Environment.TickCount).Next())
                .WithMethod("rand", (int max) => new Random(Environment.TickCount).Next(max))
                .WithMethod("p", (int p) => 5);
            }
            if (Math.IsChecked ?? false)
            {
                compiler.WithMath();
            }
            if (Date.IsChecked ?? false)
            {
                compiler.WithDate();
            }
            if (All.IsChecked ?? false)
            {
                var a = new AssemblyCallProvider()
                        .AddAssembly("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
                        .AddAssembly("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
                        .AddAssembly("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
                        .Using(Using.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                        .WithExtensionMethods();
                compiler.With(a);
            }

            if (SampleEntity.IsChecked ?? false)
            {
                compiler.WithType <SampleEntity>();
                var f = compiler.NewLambda()
                        .WithParam <SampleEntity>("s")
                        .Returns <object>()
                        .Compile(Formula.Text);
                if (f != null)
                {
                    _func = () => f(new SampleEntity());
                }
            }
            else
            {
                _func = compiler.Compile <object>(Formula.Text);
            }

            Status.Text = compiler.BuildInfo.Message;

            Button_Click_1(null, null);
        }