void Method1() { // Nếu value type xuất hiện như một parameter hoặc local variable, thì nó sẽ nằm trên stack. NormalStruct normalStruct = new NormalStruct(); // làm sao biết nằm trên stack. // ref struct variable. var refStruct = new RefStruct(); // ref struct không thể là element type của array. var points = new RefStruct[100]; var normalStructs = new NormalStruct[100]; // boxing to IInterface1. IInterface1 boxingStruct = normalStruct; // unboxing to NormalStruct var unboxingStruct = (NormalStruct)boxingStruct; // ref struct không thể là type argument. var genericClass = new GenericClass <RefStruct>(); // ref struct variable không thể sử dụng trong vòng lặp. // biến ref variable không thể ghi lại (capture) bởi một lambda expression hoặc local function. Func <int, int> square = x => x * refStruct; void localFunction() { var sum = 10 * refStruct; } }
static void Main(string[] args) { DerivedClass instance = new DerivedClass(); instance.Method(); instance.Method1(); instance.Method2(); Console.WriteLine(new string('-', 30)); BaseClass instanse1 = instance as BaseClass; instanse1.Method(); //Другие два метода недоступны IInterface1 instance2 = instance as IInterface1; instance2.Method1(); //Другие два метода недоступны IInterface2 instance3 = instance2 as IInterface2; instance3.Method2(); //Другие два метода недоступны IInterface2 instance4 = instanse1 as IInterface2; instance4.Method2(); Console.WriteLine(new string('-', 30)); BaseClass inst = new BaseClass(); IInterface2 inst1 = inst as IInterface2; //А вот это недопустимо, потому что даункаст без апкаста до этого? inst1.Method2(); }
public Class0(IInterface1 argument1, IInterface18 argument18, IInterface23 argument23, IInterface39 argument39) { Argument1 = argument1; Argument18 = argument18; Argument23 = argument23; Argument39 = argument39; }
public void FilterValues() { var inputValues = new IInterface1[] { new MyClass1(), new MyClass2(), new MyClass1(), new MyClass2() }; var outputValues = new List <MyClass1>(); var obs = new PushSubject <IInterface1>(); var filtered = obs.OfType <MyClass1>(); filtered.Subscribe(outputValues.Add); foreach (var item in inputValues) { obs.PushValue(item); } obs.Complete(); Assert.IsTrue(filtered.ToTaskAsync().Wait(5000), "The filtering should complete"); var expected = inputValues.Where(i => i is MyClass1).ToList(); for (int i = 0; i < outputValues.Count; i++) { Assert.AreSame(expected[i], outputValues[i], "all values should match"); } Assert.AreEqual(expected.Count, outputValues.Count, $"nb items from the output must match the input one"); }
static void Main(string[] args) { DerivedClass instance = new DerivedClass(); instance.Method(); instance.Method1(); instance.Method2(); Console.WriteLine(new string('-', 55)); BaseClass instance0 = instance as BaseClass; //видно только методы класса BaseClass instance0.Method(); IInterface1 instance1 = instance as IInterface1; //видно только методы интерфейса IInterface1 instance1.Method1(); IInterface2 instance2 = instance as IInterface2; //видно только методы интерфейса IInterface2 instance2.Method2(); //Delay Console.ReadKey(); }
private IInterface1 _object; // just pick one public void setObject<T>(T obj) where T : IInterface1, IComparable<T>, IEtcetera { // you now *know* that object supports all the interfaces // you don't need the compiler to remind you _object = obj; }
public void Close_OneParameterDisposedTwice(IInterface1 instance1, IInterface1 instance2) { instance1.Dispose(); instance1.Dispose(); // Noncompliant instance1.Dispose(); // Noncompliant instance2.Dispose(); // ok - only disposed once }
static void Main(string[] args) { ConcreteClass concreteClass = new ConcreteClass(); //Upcast needed IInterface1 interface1 = concreteClass as IInterface1; interface1.Method(); }
public void test_Resolve_WhenCalledForInterfaceResolvingToConcreteClassWithDependencies_ResolvesDependencies() { systemUnderTest.Register <IInterface1, Class1>(); systemUnderTest.Register <IInterface2, Class2>(); IInterface1 result = systemUnderTest.Resolve <IInterface1>(); Assert.That(result.Interface2, Is.InstanceOf <Class2>()); }
static void Main(string[] args) { TestClass test = new TestClass(); IInterface1 i1 = test; i1.SameMethod(); // will call IInterface1.SameMethod() IInterface2 i2 = test; i2.SameMethod(); // will call IInterface2.SameMethod() }
public void test_Resolve_WhenCalledTwiceForInterfaceResolvingToConcreteClassWithTransientDependencies_ResolvesDependenciesTwice() { systemUnderTest.Register <IInterface1, Class1>(); systemUnderTest.Register <IInterface2, Class2>(LifeStyleType.Transient); IInterface1 result1 = systemUnderTest.Resolve <IInterface1>(); IInterface1 result2 = systemUnderTest.Resolve <IInterface1>(); Assert.That(result1.Interface2 == result2.Interface2, Is.False); }
static void Main(string[] args) { ConcreteClass concreteClass = new ConcreteClass(); concreteClass.Method(); IInterface1 interface1 = concreteClass as IInterface1; interface1.Method(); }
public void ItShouldResolveInterface1() { // Act IInterface1 actual = _container.GetService <IInterface1>(); // Assert actual .Should() .NotBeNull() .And.BeOfType <ConcreteDerivedClass>(); }
public void TheInterfacesShouldResolveToTheSameInstances() { // Act IInterface1 actual = _container.GetService <IInterface1>(); // Assert actual .Should() .NotBeNull() .And.BeSameAs(_container.GetService <IInterface2>()); }
static void Main(string[] args) { ConcreteClass instance = new ConcreteClass(); IInterface1 instance1 = instance as IInterface1; instance1.Method(); IInterface2 instance2 = instance as IInterface2; instance2.Method(); Console.ReadKey(); }
static void Main(string[] args) { MyClass my = new MyClass(); my.M(); IInterface1 i1 = my; i1.M(); IInterface2 i2 = my; i2.M(); }
static void Main(string[] args) { DerivedClass instance = new DerivedClass(); //instance. - не видит методов интерфейса //Для этого апкастим к базовому интерфейсному типу IInterface1 instance1 = instance as IInterface1; instance1.Method(); IInterface2 instance2 = instance as IInterface2; instance2.Method(); }
static void Main() { ConcreteClass instance = new ConcreteClass(); //instance.Method (); IInterface1 instance1 = instance as IInterface1; instance1.Method(); IInterface2 instance2 = instance as IInterface2; instance2.Method(); // Delay. Console.ReadKey(); }
static void Main(string[] args) { TestInterface te = new TestInterface(); te.Test(); IInterface1 i1 = te; i1.Show(); IInterface2 i2 = te; i2.Show(); Console.ReadLine(); }
static void Main(string[] args) { ConcreteClass instance = new ConcreteClass(); // instance. ----Ничего не видно IInterface1 instance1 = instance as IInterface1; instance1.Method();//один метод //ОН ВИДЕН ПОТОМУ, ЧТО ВСЕ МЕТОДЫ В ИНТЕРФЕЙСАХ ПО УМОЛЧАНИЮ PUBLIC!!! IInterface2 instance2 = instance as IInterface2; instance2.Method(); instance2.Method();//другой метод //ОН ВИДЕН ПОТОМУ, ЧТО ВСЕ МЕТОДЫ В ИНТЕРФЕЙСАХ ПО УМОЛЧАНИЮ PUBLIC!!! //Delay Console.ReadKey(); }
public void InterfacesTest() { Implementation imp = new Implementation(); IInterface1 i1 = imp; IInterface2 i2 = imp; Console.WriteLine("A call from implementation directly"); imp.DoSmth(); Console.WriteLine("A call from interface1 "); i1.DoSmth(); Console.WriteLine("A call from interface2 "); i2.DoSmth(); }
static void Main(string[] args) { DerivedClass instance = new DerivedClass(); // instance. -- //На экземпляре не видим private методов интерфейсов! //Приведем экземпляр класса DerivedClasss - instance, к базовому интервейсному типу IInterface1 IInterface1 instance1 = instance as IInterface1; instance1.Method(); IInterface2 interface2 = instance as IInterface2; interface2.Method(); //Но мы можем увидить методы, которые public instance.Method3(); //Delay Console.ReadKey(); }
static void Main(string[] args) { ConcreteClass instance = new ConcreteClass(); instance.Method1(); instance.Method2(); IInterface1 instance1 = instance as IInterface1; instance1.Method1(); IInterface2 instance2 = instance as IInterface2; //тут у нас есть доступ и к Method1 и к Method2 instance2.Method1(); // т.к IInterface2 наследуется от IInterface1 instance2.Method2(); //Delay Console.ReadKey(); }
static void Main(string[] args) { ConcreteClass instance = new ConcreteClass(); instance.Method1(); instance.Method2(); IInterface1 instance2 = instance as IInterface1; instance2.Method1(); IInterface2 instance3 = instance2 as IInterface2; instance3.Method1(); instance3.Method2(); Console.WriteLine(new string('-', 30)); ConcreteClass concreteClass = new ConcreteClass(); IInterface2 interface2 = concreteClass as IInterface2; interface2.Method1(); interface2.Method2(); }
public Wrap([TestContract("a1")] IInterface1 s1, [TestContract("a2")] IInterface1 s2) { this.s1 = s1; this.s2 = s2; }
public ChildClass(IInterface1 interface1) { this.Interface1 = interface1; }
public ParentClass(IInterface1 interface1) { this.Interface1 = interface1; }
public void Test1(IInterface1 input) { input.MethodI(); }
public void ExecTest() { Test1(new ClassB()); Test1(new ClassC()); var probeerMaar = new IInterface1(); }
public Implementation2(Guid id, IInterface1 interface1) { Id = id; }
public Class4(IInterface1 p1, IInterface2 p2) {}
public Class3(IInterface1 p1, IInterface2 p2, int p3) {}
public CircularReference2(IInterface1 arg) { }
public SelfBoundService1(int param1, double param2, IInterface1 param3) { Property1 = param1; Property2 = param2; Property3 = param3; }