예제 #1
0
        public void Test_Visitor5()
        {
            Visitor <string> visitor = ConfigureVisitor();

            IVehicle vehicle1 = new Car();
            string   text1    = visitor.Call(vehicle1);

            Assert.Equal("car", text1);

            IVehicle vehicle2 = new Moto();
            string   text2    = visitor.Call(vehicle2);

            Assert.Equal("moto", text2);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Visitor<string> visitor = ConfigureVisitor();

            IVehicle vehicle = new Car();
            string text = visitor.Call(vehicle);
            Console.WriteLine(text);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            Visitor <IVehicle, string> visitor = ConfigureVisitor();

            IVehicle vehicle = new Car();
            string   text    = visitor.Call(vehicle);

            //visitor.Call(new Fruit()); // doesn't compile
            Console.WriteLine(text);
        }
        public static void Main(string[] args)
        {
            Visitor <string> visitor = new Visitor <string>();

            visitor.When <Car>(car => "car")
            .When <Moto>(moto => "moto");

            IVehicle vehicle = new Car();
            string   text    = visitor.Call(vehicle);

            Console.WriteLine(text);
        }