示例#1
0
        static void Main()
        {
            var context = new ComponentContext();

            context.ProcessCompositionXmlFromResource("Compositional.Composer.Samples.Basic.CalculatorComposition.xml");

            var classEmitter = context.GetComponent <IClassEmitter>();
            IEmittedTypeHandler emittedTypeHandler = new TestEmittedTypeHandler();

            context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IAdder))));
            context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IMultiplier))));
            context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IDivider))));

            context.GetComponent <IProgramRunner>().Run();
        }
示例#2
0
        static void Main()
        {
            var context      = new ComponentContext();
            var classEmitter = context.GetComponent <IClassEmitter>();

            IEmittedTypeHandler emittedTypeHandler = new TestEmittedTypeHandler();

            var adder      = (IAdder)classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IAdder));
            var multiplier = (IMultiplier)classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IMultiplier));
            var divider    = (IDivider)classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IDivider));

            Console.WriteLine("67 + 12 = {0}", adder.Add(67, 12));
            Console.WriteLine();

            Console.WriteLine("67 * 12 = {0}", multiplier.Multiply(67, 12));
            Console.WriteLine();

            Console.WriteLine("67 / 12 = {0}", divider.Divide(67, 12));
            Console.WriteLine();

            Console.WriteLine("67 % 12 = {0}", divider.Remainder(67, 12));
            Console.WriteLine();
        }