Exemplo n.º 1
0
        public void thing()
        {
            thing1.Add(new Rosemary(), new Thyme());
            thing2.Add(new Basil(), new Thyme());
            thing3.Add(new Chives(), new Basil());
            thing4.Add(default(T), default(T1));
            moreThing.Add(new Basil(), new Rosemary());
            anotherThingEntirely.Method("", 1);

            thing3.Add(new Chives(), new Basil());
            thing3.Add(new Chives(), new Basil());
            anotherThingEntirely.Method("", 1);
        }
Exemplo n.º 2
0
 public static void TheMethodITest(IInterface dep)
 {
     for (var i = 0; i < 10; i++)
     {
         Debug.WriteLine("{0}:{1}", i, dep.Method(i));
     }
 }
Exemplo n.º 3
0
        public void TestInterfaceProxyMethod()
        {
            IInterface duck = DuckTyping.Cast <IInterface>(new Duck());

            duck.Method();

            duck.Method(Duck.A, Duck.B, Duck.C, Duck.D);

            string stringValue = "String value.";

            Assert.AreEqual(stringValue, duck.Method(stringValue), "Method returned wrong string value.");
            Assert.IsNull(duck.Method(null), "Passing and returning a null value failed.");

            int intValue = 5;

            Assert.AreEqual(intValue, duck.Method(intValue), "Method returned wrong int value.");

            Assert.IsTrue(duck.BestMatchMethod(stringValue), "When generating the proxy class, the best matching method overload on the duck class was not chosen to forward calls to.");
        }
Exemplo n.º 4
0
        static void Main()
        {
            DerivedClass instance = new DerivedClass();
            instance.Method();

            IInterface instance1 = instance as IInterface;
            instance1.Method();

            // Delay.
            Console.ReadKey();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            DerivedClass instance = new DerivedClass();

            instance.Method();

            IInterface instance1 = instance as IInterface;

            instance1.Method();

            Console.ReadKey();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            ConcretClass instance = new ConcretClass();

            instance.Method();

            IInterface instance1 = instance as IInterface;

            instance1.Method();

            Console.ReadKey();

            // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app!
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            DerivedClass derivedClass = new DerivedClass();

            derivedClass.Method();

            IInterface interface1 = derivedClass as IInterface;

            interface1.Method();

            BaseClass baseClass = derivedClass as BaseClass;

            baseClass.Method();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            MyStruct my;

            my.Method();

            IInterface boxed = my;

            boxed.Method();

            MyStruct undox = (MyStruct)boxed;

            undox.Method();
        }
        public void DynamicLoadInterface()
        {
            MyLoader loader = new MyLoader();

            loader.Load();
            IInterface impl = loader.Instantiate <IInterface>(
                new Identifier("ExternalAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
                               "Devspace.HowToCodeDotNet01.LoadingAssembliesWithoutHassles.Implementation"));

            // Show what assemblies are loaded
            ToStringFormatState.ToggleToSpaces();
            Console.WriteLine(ToStringFormatState.DefaultFormat.FormatBuffer(loader.ToString()));
            impl.Method();
        }
Exemplo n.º 10
0
        static void Main()
        {
            MyStruct my;

            my.Method();
            // Упаковка (Boxing).
            IInterface boxed = my;

            boxed.Method();

            // Распаковка объекта (UnBoxing).
            MyStruct unBoxed = (MyStruct)boxed;

            // Delay.
            Console.ReadKey();
        }
        public void ManualDynamicLoad()
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(AssemblyName.GetAssemblyName(
                                                                                      @"C:\Documents and Settings\cgross\Desktop\projects\HowToCodeDotNet\Volume01\ExternalAssembly\bin\Debug\ExternalAssembly.dll"));
            Object @object;

            @object = assembly
                      .CreateInstance("Devspace.HowToCodeDotNet01.LoadingAssembliesWithoutHasseles.Implementation");

            Assert.IsNotNull(@object);
            IInterface impl = @object as IInterface;

            if (impl != null)
            {
                impl.Method();
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            MyStruct instance;

            Console.WriteLine(instance.GetHashCode()); //HashCod'ы ОДИНАКОВЫ
            instance.Method();

            //Упаковка Boxing
            IInterface boxed = instance;

            Console.WriteLine(boxed.GetHashCode());   //HashCod'ы ОДИНАКОВЫ
            boxed.Method();

            //Распаковка UnBoxing
            MyStruct unBoxed = (MyStruct)boxed;

            Console.WriteLine(unBoxed.GetHashCode());  //HashCod'ы ОДИНАКОВЫ
            unBoxed.Method();

            //Delay
            Console.ReadKey();
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="diInterface"></param>
        /// <param name="logger"></param>
        public ValuesController(Context context, IInterface diInterface, ILogger <ValuesController> logger)
        {
            _context = context;
            _logger  = logger;

            if (!_context.Values.Any())
            {
                _context.Values.Add(new ValueItem {
                    Name = diInterface.Method()
                });
                _context.Values.Add(new ValueItem {
                    Name = "Item1"
                });
                _context.Values.Add(new ValueItem {
                    Name = "Item2"
                });
                _context.Values.Add(new ValueItem {
                    Name = "Item3"
                });
                _context.SaveChanges();
            }

            _logger.LogDebug("Controller constructor was called.");
        }
        public void FactoryDynamicLoad()
        {
            IInterface impl = LocalDynamicFactory.Factory.CreateInstance();

            impl.Method();
        }