Exemplo n.º 1
0
        public static void test1()
        {
            IFoProperty[] props =
            {
                new FoProperty <string>("xxx",   "Stephen R. Strong"),
                new FoProperty <double>("cost",                  100),
                new FoProperty <double>("tax",                   .33),
                new FoProperty <double>("total", () => { return(1000); })
            };


            var comp1 = new FoComponent("Comp1");

            comp1.Properties.AddList(props);
            var cost  = comp1.Reference <FoProperty <double> >("cost");
            var tax   = comp1.Reference <FoProperty <double> >("tax");
            var total = comp1.Reference <FoProperty <double> >("total");

            total.Formula = () => { return(1000 * cost.Value * tax.Value); };


            Console.WriteLine($"==========================");
            Console.WriteLine($"Component: {comp1.MyName}");
            Console.WriteLine($"{comp1.toJson()}");
            Console.WriteLine($"..........................");

            cost.Value = 1;
            Console.WriteLine($"==========================");
            Console.WriteLine($"Component: {comp1.MyName}");
            Console.WriteLine($"{comp1.toJson()}");
            Console.WriteLine($"..........................");
        }
Exemplo n.º 2
0
        public static void test1()
        {
            var prop1 = new FoProperty <string>("xxx", "Stephen R. Strong");

            prop1.toJson();

            var prop2a = new FoProperty <double>("cost", 100);

            prop2a.toJson();

            var prop2b = new FoProperty <double>("tax", .33);

            prop2b.toJson();

            Func <double> func   = () => { return(1000 * prop2a.Value * prop2b.Value); };
            var           prop2c = new FoProperty <double>("total", func);

            prop2c.toJson();

            string[] stuff = { "one", "two", "three", "5" };
            var      prop3 = new FoCollection <string>("count", stuff);

            double[] data  = { 1, 2, 3, 4, 5, 6, 7 };
            var      prop4 = new FoCollection <double>("number", data);
            var      prop5 = new FoCollection <double>("number");

            var comp1 = new FoComponent("my Comp");

            // Console.WriteLine($" to string {prop1}");
            // Console.WriteLine($" to string {prop2}");
            // Console.WriteLine($" to string {prop3}");
            // Console.WriteLine($" to string {prop4}");
            // Console.WriteLine($" to string {prop5}");

            IFoProperty[] props = { prop1, prop2a, prop2b, prop2c };
            comp1.Properties.AddList(props);

            Console.WriteLine($" comp {comp1}");

            comp1.toJson();

            prop2b.Value = .505;

            comp1.toJson();

            prop2c.Formula = () => { return(prop2a.Value * prop2b.Value); };

            comp1.toJson();


            //prop4.asJson(prop4);
            //prop5.asJson(prop5);
        }
Exemplo n.º 3
0
        public static void test2()
        {
            IFoProperty[] props =
            {
                new FoProperty <string>("proper name", "Stephen R. Strong"),
                new FoProperty <double>("cost",                        100),
                new FoProperty <double>("tax",                         .33),
                new FoProperty <double>("total",       () => { return(1000); })
            };

            IFoComponent[] comps =
            {
                new FoComponent("Comp1", props),
                new FoComponent("Comp2", props),
                new FoComponent("Comp3", props),
            };

            var root  = new FoComponent("Root", comps);
            var total = new FoProperty <double>("total cost", () => {
                double result = root.SumOver("cost");
                return(result);
            });

            root.Properties.Add(total);

            Console.WriteLine($"===========================");
            // Console.WriteLine($"{root.Properties.toJson()}");
            Console.WriteLine($"{root.toJson()}");
            Console.WriteLine($"..........................");

            root.saveToFile(@"data/test2.json");
        }
Exemplo n.º 4
0
        public static void test4()
        {
            var body = JSONExtensions.readFromFile(@"data/create_root.json");
            var name = body.GetProperty("MyName");
            var root = new FoComponent(name.ToString());

            root.saveToFile(@"data/test4.json");

            var handle = Activator.CreateInstance(root.GetType()) as FoComponent;

            handle.MyName = "ffrfrf";

            Console.WriteLine($"{handle.toJson()}");
            Console.WriteLine($"===========================");
            Console.WriteLine($"{root.toJson()}");
            Console.WriteLine($"..........................");
        }
Exemplo n.º 5
0
        public static void test3()
        {
            IFoProperty[] props =
            {
                new FoProperty <string>("proper name", "Stephen R. Strong"),
            };


            var root = new FoComponent("Root", props);

            Console.WriteLine($"===========================");
            // Console.WriteLine($"{root.Properties.toJson()}");
            Console.WriteLine($"{root.toJson()}");
            Console.WriteLine($"..........................");

            root.saveToFile(@"data/test3.json");
        }