コード例 #1
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");
        }
コード例 #2
0
        public void Test1()
        {
            var prop2a = new FoProperty <double>("cost", 100);

            prop2a.toJson();

            Assert.Equal(100, prop2a.Value);
        }
コード例 #3
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);
        }