예제 #1
0
        /// <summary>
        /// Entry method
        /// </summary>
        /// <param name="args">Command line arguments</param>
        public static void Main(string[] args)
        {
            var target = new HelloWorldTarget();

            // Visual Studio won't show the Hello() method through intellisense,
            // and it may provide a visual cue that the method name is invalid
            // (e.g. red squiggly underline). It will compile, though :-)
            Console.WriteLine(target.Hello());

            // HelloAgain() is explicitly implemented in the mixin definition.
            // Because of this, it cannot be directly invoked.
            // If you uncomment this line, then Visual Studio intellisense will
            // complain identically to the above call to Hello(). This time,
            // though, it is correct in believing that the method is unavailable.
            //     (uncomment following line and try to compile to see this)
            // Console.WriteLine(target.HelloAgain());

            // Casting your target to the interface makes intellisense easier
            // to work with. It also allows you to call interface-scoped members.
            var targetAsInterface = target as MyMixinDefinitions.IHelloWorld;

            Console.WriteLine(targetAsInterface.HelloAgain());

            // Calling a generic method works as you'd expect.
            Console.WriteLine(target.HelloEcho("Echo this string, and then echo a number in the next line."));
            Console.WriteLine(target.HelloEcho(42));

            // now let's look at how constructor calls work
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            // start with a call to the parameterless constructor
            // notice that the static type initializer gets called at some point (no guarantee when, just that it's before the type is used)
            // notice that the implementation mixin code has been cloned into the parameterless constructor
            var parameterless = new FunWithConstructorsTarget();

            // now make a call to the constructor that takes a bool
            // again, the mixin implementation constructor code was copied here
            var boolParameter = new FunWithConstructorsTarget(false);

            // last, make a call to the constructor that takes a number
            // this constructor chains to the bool constructor
            // notice that the mixin implementation constructor code only runs as part of the bool constructor
            var intParamater = new FunWithConstructorsTarget(34);
        }
예제 #2
0
        /// <summary>
        /// Entry method
        /// </summary>
        /// <param name="args">Command line arguments</param>
        public static void Main(string[] args)
        {
            var target = new HelloWorldTarget();

            // Visual Studio won't show the Hello() method through intellisense,
            // and it may provide a visual cue that the method name is invalid
            // (e.g. red squiggly underline). It will compile, though :-)
            Console.WriteLine(target.Hello());

            // HelloAgain() is explicitly implemented in the mixin definition.
            // Because of this, it cannot be directly invoked.
            // If you uncomment this line, then Visual Studio intellisense will
            // complain identically to the above call to Hello(). This time,
            // though, it is correct in believing that the method is unavailable.
            //     (uncomment following line and try to compile to see this)
            // Console.WriteLine(target.HelloAgain());

            // Casting your target to the interface makes intellisense easier
            // to work with. It also allows you to call interface-scoped members.
            var targetAsInterface = target as MyMixinDefinitions.IHelloWorld;
            Console.WriteLine(targetAsInterface.HelloAgain());

            // Calling a generic method works as you'd expect.
            Console.WriteLine(target.HelloEcho("Echo this string, and then echo a number in the next line."));
            Console.WriteLine(target.HelloEcho(42));

            // now let's look at how constructor calls work
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            // start with a call to the parameterless constructor
            // notice that the static type initializer gets called at some point (no guarantee when, just that it's before the type is used)
            // notice that the implementation mixin code has been cloned into the parameterless constructor
            var parameterless = new FunWithConstructorsTarget();

            // now make a call to the constructor that takes a bool 
            // again, the mixin implementation constructor code was copied here
            var boolParameter = new FunWithConstructorsTarget(false);

            // last, make a call to the constructor that takes a number
            // this constructor chains to the bool constructor
            // notice that the mixin implementation constructor code only runs as part of the bool constructor
            var intParamater = new FunWithConstructorsTarget(34);
        }