コード例 #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);
        }
コード例 #2
0
 public static void TheMethodITest(IInterface dep)
 {
     for (var i = 0; i < 10; i++)
     {
         Debug.WriteLine("{0}:{1}", i, dep.Method(i));
     }
 }
コード例 #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.");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: HVAHAGN/Interfaces
        static void Main()
        {
            DerivedClass instance = new DerivedClass();
            instance.Method();

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

            // Delay.
            Console.ReadKey();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            DerivedClass instance = new DerivedClass();

            instance.Method();

            IInterface instance1 = instance as IInterface;

            instance1.Method();

            Console.ReadKey();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: gevorgyan007/inheritance
        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!
        }
コード例 #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();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            MyStruct my;

            my.Method();

            IInterface boxed = my;

            boxed.Method();

            MyStruct undox = (MyStruct)boxed;

            undox.Method();
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        static void Main()
        {
            MyStruct my;

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

            boxed.Method();

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

            // Delay.
            Console.ReadKey();
        }
コード例 #11
0
        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();
            }
        }
コード例 #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();
        }
コード例 #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.");
        }
コード例 #14
0
        public void FactoryDynamicLoad()
        {
            IInterface impl = LocalDynamicFactory.Factory.CreateInstance();

            impl.Method();
        }