コード例 #1
0
        static void Main()
        {
            var swan       = new Swan();
            var swanAsDuck = swan as IDuck;

            //Condition below is never satisfied with default features of CLR. This is so because although
            //swan matches signature of IDuck interface, CLR requires swan to inherit it from IDuck interface
            //ecplicitly.
            Console.WriteLine("Attempting to use swan as a duck...");
            if (swan is IDuck || swanAsDuck != null)
            {
                swanAsDuck.Walk();
                swanAsDuck.Swim();
                swanAsDuck.Quak();
            }
            else
            {
                Console.WriteLine("Attempt failed......");
            }
            Console.ReadKey();
            Console.WriteLine("Attempting using dynamic language runtime....");
            //This however can be changed by using a few features like-
            //DLR
            DoDuckLikeThings(swan);
            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var swan = new Swan();

            DoDuckLikeThings(swan);

            Console.ReadKey();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var swan = new Swan();

            var swanAsDuck = swan as IDuck;

            if(swan is IDuck || swanAsDuck != null)
            {
                swanAsDuck.Walk();
                swanAsDuck.Swim();
                swanAsDuck.Quack();
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Swan swan       = new Swan();
            var  swanAsDuck = swan as IDuck;

            if (swan is IDuck || swanAsDuck != null)
            {
                swan.Walk();
                swan.Swim();
                swan.Quack();
            }
            Console.ReadLine();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var swan = new Swan();

            var swanAsDuck = Impromptu.ActLike<IDuck>(swan);

            if(swanAsDuck != null)
            {
                swanAsDuck.Walk();
                swanAsDuck.Swim();
                swanAsDuck.Quack();
            }

            Console.ReadKey();
        }