public ConsoleMessage(string name, int age, IAnotherInterface iAnotherInterface) { Name = name; Age = age; _AnotherClass = iAnotherInterface; }
public void ExportAttribute_Test(ImportSomeInterface import, IAnotherInterface anotherInterface) { Assert.NotNull(import); Assert.Equal(15, import.SomeValue); Assert.NotNull(anotherInterface); }
static void Main() { SomeDerivedClass obj = new SomeDerivedClass(); ISomeInterface isi = obj; IAnotherInterface iai = obj; isi.SomeMethod(); iai.SomeMethod(); iai.AnotherMethod(); }
public virtual void OnBom() { IEnumerator e = m_anotherInterfaceList.GetEnumerator(); for ( ; e.MoveNext(); ) { IAnotherInterface sink = e.Current as IAnotherInterface; sink.OnBom(); } }
static void Main(string[] args) { // 這裡將會建立 DI 容器 IUnityContainer container = new UnityContainer(); // 進行抽象型別與具體實作類別的註冊 container.RegisterType <IAnotherInterface, AnotherClass>(); container.RegisterType <IAnotherInterface, NewClass>("New"); // ConsoleMessage 類別內有三個建構式 // 使用 InjectionConstructor 指定使用哪個建構式 container.RegisterType <IMessage, ConsoleMessage>( new InjectionConstructor("Vulcan", 50, typeof(IAnotherInterface)), new InjectionProperty("Cost", 999.168) ); // 進行抽象型別的具體實作物件的解析 IMessage message = container.Resolve <IMessage>(); // 執行取得物件的方法 message.Write("Hi Vulcan"); Console.WriteLine("Press any key for continuing..."); Console.ReadKey(); IAnotherInterface newClass = container.Resolve <IAnotherInterface>("New"); IMessage messageResolveOverride = container.Resolve <IMessage>( new ParameterOverride("name", "Will"), new ParameterOverride("age", 99), new ParameterOverride("iAnotherInterface", newClass), new PropertyOverride("Cost", 168.123)); messageResolveOverride.Write("Hi Vulcan"); Console.WriteLine("Press any key for continuing..."); Console.ReadKey(); }
static void Main(string[] args) { Product product = new Product("123", "213"); Furniture tech = new Furniture("456", "789", "456789"); closet closet1 = new closet(); IMyInterface myInterface = closet1; IAnotherInterface[] arr = new IAnotherInterface[3]; arr[0] = product; arr[1] = tech; arr[2] = closet1; Console.WriteLine(product.ToString()); Console.WriteLine(tech.ToString()); Console.WriteLine(closet1.MyFunc()); Console.WriteLine(myInterface.MyFunc()); Console.WriteLine($"myInterface is IMyInterface = {myInterface is IMyInterface}"); Console.WriteLine($"myInterface is Tabet = {myInterface is closet}"); foreach (IAnotherInterface x in arr) { Print.IAmPrinting(x); } }
static void Main(string[] args) { Product product = new Product("123", "213"); Sweets tech = new Sweets("456", "789", "456789"); Flower tablet = new Flower(); IMyInterface myInterface = tablet; IAnotherInterface[] arr = new IAnotherInterface[3]; arr[0] = product; arr[1] = tech; arr[2] = tablet; Console.WriteLine(product.ToString()); Console.WriteLine(tech.ToString()); Console.WriteLine(tablet.MyFunc()); Console.WriteLine(myInterface.MyFunc()); Console.WriteLine($"myInterface is IMyInterface = {myInterface is IMyInterface}"); Console.WriteLine($"myInterface is Tabet = {myInterface is Flower}"); foreach (IAnotherInterface x in arr) { Print.IAmPrinting(x); } }
public static void IAmPrinting(IAnotherInterface obj) { Console.WriteLine(obj.ToString()); }
private static void SomeFunction2(IAnotherInterface anotherInterface) { }
public void Handle(IAnotherInterface message) { calls.Add("AnotherHandler: another_interface"); }
static void Main(string[] args) { Product product = new Product("123", "213", 100); Tech tech = new Tech("456", "789", "456789", 200); Tablet tablet = new Tablet(); Lab lab = new Lab(6); Scanner scanner = new Scanner("2223", "32131", "11123", "231", 22360); tablet.info.price = 300; IAnotherInterface[] arr = new IAnotherInterface[3]; arr[0] = product; arr[1] = tech; arr[2] = tablet; try { Lab WrongLab = new Lab(100); WrongLab.Del(tablet); //arr[4].ToString(); lab.Add(product); lab.Add(tech); lab.Add(tablet); lab.Add(new Scanner()); lab.Add(new Printer()); lab.Add(new Product()); //lab.Add(new Product()); lab.show(); controller.show(lab); controller.sort(lab); lab.show(); lab.Del(tablet); //lab.Del(scanner); lab.show(); } catch (LabIsFull ex) { Console.WriteLine("LabIsFull Exception"); Console.WriteLine(ex.Message); } catch (ElementDoesNotExist ex) { Console.WriteLine("ElementDoesNotExist Exception"); Console.WriteLine(ex.Message); } catch (LabIsEmpty ex) { Console.WriteLine("LabIsEmpty Exception"); Console.WriteLine(ex.Message); } catch (WrongSize ex) { Console.WriteLine("WrongSize Exception"); Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine("Another Exception"); Console.WriteLine(ex.Message); } }
void RegisterInterface( IAnotherInterface sut ) { Assert.IsType<MultipleInterfaces>( sut ); }
static void Main(string[] args) { Product product = new Product("org1", "prod1", 200, 700); Furniture furn = new Furniture("org2", "prod2", "furniture1", 600, 2000); closet closet1 = new closet(); warehouse warehouse1 = new warehouse(10); closet1.info.price = 300; closet1.info.mas = 3000; IAnotherInterface[] arr = new IAnotherInterface[3]; arr[0] = product; arr[1] = furn; arr[2] = closet1; try { warehouse WrongLab = new warehouse(100); //WrongLab.Del(closet1); //arr[4].ToString(); warehouse1.Add(product); warehouse1.Add(furn); warehouse1.Add(closet1); warehouse1.Add(new Furniture("org2", "prod4", "furniture2", 1000, 1500)); warehouse1.Add(new Product("org1", "prod5", 400, 200)); warehouse1.show(); controller.sort(warehouse1); warehouse1.show(); warehouse1.Del(closet1); warehouse1.show(); Console.WriteLine("asdasdasdsadasdasd"); warehouse1.sortByMas(700); //WrongLab.Del(scanner); } catch (LabIsFull ex) { Console.WriteLine("WarehouseIsFull Exception"); Console.WriteLine(ex.Message); } catch (ElementDoesNotExist ex) { Console.WriteLine("ElementDoesNotExist Exception"); Console.WriteLine(ex.Message); } catch (LabIsEmpty ex) { Console.WriteLine("WarehouseIsEmpty Exception"); Console.WriteLine(ex.Message); } catch (WrongSize ex) { Console.WriteLine("WrongSize Exception"); Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine("Another Exception"); Console.WriteLine(ex.Message); } }
static void Main(string[] args) { Product product = new Product("123", "213", 100, 500); Sweets nyam = new Sweets("456", "789", "456789", 200, 1300); Flower rose = new Flower(); Gift gift = new Gift(10); rose.info.price = 300; IAnotherInterface[] arr = new IAnotherInterface[3]; arr[0] = product; arr[1] = nyam; arr[2] = rose; try { Gift WrongLab = new Gift(100); WrongLab.Del(rose); //arr[4].ToString(); gift.Add(product); gift.Add(nyam); gift.Add(rose); gift.Add(new Sweets()); gift.Add(new Clocks()); gift.Add(new Product()); //lab.Add(new Product()); gift.show(); controller.show(gift); controller.sort(gift); gift.show(); gift.Del(rose); //lab.Del(scanner); gift.show(); } catch (LabIsFull ex) { Console.WriteLine("GiftIsFull Exception"); Console.WriteLine(ex.Message); } catch (ElementDoesNotExist ex) { Console.WriteLine("ElementDoesNotExist Exception"); Console.WriteLine(ex.Message); } catch (LabIsEmpty ex) { Console.WriteLine("GiftIsEmpty Exception"); Console.WriteLine(ex.Message); } catch (WrongSize ex) { Console.WriteLine("WrongSize Exception"); Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine("Another Exception"); Console.WriteLine(ex.Message); } }