public static int InterfaceTest4() { InterfaceTestClassB tc = new InterfaceTestClassB(); IInterfaceA a = tc; return(a.A()); }
public static bool InterfaceTest4() { TestClassB tc = new TestClassB(); IInterfaceA a = tc; bool result = (a.A() == 1); return(result); }
public void CanUseInterfaceInterceptionAdditionalInterfacesThroughConfiguration() { IUnityContainer container = GetContainer("CanUseInterfaceInterceptionAdditionalInterfacesThroughConfiguration"); IInterfaceA proxy = container.Resolve <IInterfaceA>(); IAdditionalInterface casted = (IAdditionalInterface)proxy; int value = casted.DoNothing(); Assert.AreEqual <int>(100, value); }
public void CheckObjectInclusion() { ClassC c = new ClassC(); ClassA a = new ClassA(); ClassNotA na = new ClassNotA(); IInterfaceA ia = null; Assert.True(c.DoesInclude(a)); Assert.False(c.DoesInclude(ia)); Assert.False(c.DoesInclude(na)); }
public void InterfaceInterceptionWithoutAdditionalInterfaces() { DoNothingInterceptionBehavior.Reset(); IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1]; behaviourArray[0] = new DoNothingInterceptionBehavior(); IInterfaceA target = new ImplementsInterface(); IInterfaceA proxy = Intercept.ThroughProxy(target, new TransparentProxyInterceptor(), behaviourArray); proxy.TargetMethod(); Assert.AreEqual("Called", DoNothingInterceptionBehavior.PreCalled); Assert.AreEqual("Called", DoNothingInterceptionBehavior.PostCalled); }
public void CanUseInterfaceInterceptorThroughConfiguration() { IUnityContainer container = GetContainer("CanUseInterfaceInterceptorThroughConfiguration"); DoNothingInterceptionBehavior.Reset(); IInterfaceA abc = container.Resolve <IInterfaceA>(); abc.TargetMethod(); Assert.AreEqual <string>("Called", DoNothingInterceptionBehavior.PreCalled); Assert.AreEqual <string>("Called", DoNothingInterceptionBehavior.PostCalled); }
static void Main(string[] args) { DerivedClass derivedClass = new DerivedClass(); IInterfaceA derivedClassUpToA = derivedClass as IInterfaceA; derivedClassUpToA.Method(); IInterfaceB derivedClassUpToB = new DerivedClass(); derivedClassUpToB.Method(); }
static void Main(string[] args) { DerivedClass derivedClass = new DerivedClass(); // недоступны методы интерфейсов тк в derivedClass они private IInterfaceA derivedClassUpToA = derivedClass; derivedClassUpToA.Method(); IInterfaceB derivedClassUpToB = derivedClass as IInterfaceB; derivedClassUpToB.Method(); }
public void CheckObjectInclusion() { var mgr = SetUp(); ClassC c = new ClassC(); ClassA a = new ClassA(); ClassNotA na = new ClassNotA(); IInterfaceA ia = null; Assert.True(mgr.CheckObjectInclusion(c, a)); Assert.False(mgr.CheckObjectInclusion(c, ia)); Assert.False(mgr.CheckObjectInclusion(c, na)); }
static void Main(string[] args) { DerivedClass dClass = new DerivedClass(); IInterfaceA dClassUpToA = dClass; dClassUpToA.Method(); IInterfaceB dClassUpToB = dClass as IInterfaceB; dClassUpToB.Method(); Console.ReadKey(); }
public void CanConfigureMultipleAdditionalInterfacesThroughConfiguration() { IUnityContainer container = GetContainer("CanConfigureMultipleAdditionalInterfacesThroughConfiguration"); IInterfaceA proxy = container.Resolve <IInterfaceA>(); IAdditionalInterface casted = (IAdditionalInterface)proxy; int value = casted.DoNothing(); Assert.AreEqual <int>(100, value); IAdditionalInterface1 casted1 = (IAdditionalInterface1)proxy; int value1 = casted1.DoNothing1(); Assert.AreEqual <int>(200, value1); }
static void Main(string[] args) { //InterfaceImplA obj = new InterfaceImplA(); //obj.MyMethod(); //Not possible since it's explicit implementation IInterfaceA obj1 = (InterfaceImplA) new InterfaceImplA(); obj1.MyMethod(); InterfaceImplB obj2 = new InterfaceImplB(); obj2.MyMethod(); Console.Read(); }
//because class is internal, you public Run method will be treated as internal. static public void Run() { SomeExplicitClassExample sc = new SomeExplicitClassExample(); sc.Walk(); //sc.Jump() wont work IInterfaceA sc2 = new SomeExplicitClassExample(); sc2.Jump(); //sc2.Walk() wont work IInterfaceA sc3 = (sc as IInterfaceA); //through casting, you can do new SomeExplicitClassExample() or even (IInterfaceA)sc sc3.Jump(); //sc3.Walk() wont work }
static internal void Run() { //Implicit IInterfaceA @interface = new ImplementedClass(); //Note @interface at runtime will resolve to the ImplementedClass class. @interface.Hello(); //Explicit ImplementedClass @implementedClass = (ImplementedClass)@interface; //Note @interface is secretly a ImplementedClass type, see above where a ImplementedClass was instantiated. @implementedClass.Hello(); //is - validate or check type, return true or false //Note: @interface is secretly a ImplementedClass type, see above where a ImplementedClass was instantiated. if (@interface is IInterfaceA) { Console.WriteLine("The interface intance can be directly assigned to InterfaceA."); } if (@interface is ImplementedClass) { Console.WriteLine("The interface intancecan can be explicitly casted and assigned to ImplementedClass."); } if (@implementedClass is IInterfaceA) { Console.WriteLine("The class intance can be implicited assigned to InterfaceA."); } if (implementedClass is ImplementedClass) { Console.WriteLine("The class intance can be directly assigned to ImplementedClass."); } //as - validate or check type, return value or null IInterfaceA @interface2 = @interface as IInterfaceA; //as retunrs IInterfaceA which can be assigned to type IInterfaceA directly. interface2.Hello(); IInterfaceA @interface3 = @interface as ImplementedClass; //as returns ImplementedClass, which implicitly converts to IInterfaceA @interface3.Hello(); ImplementedClass @implementedClass2 = (ImplementedClass)(@implementedClass as IInterfaceA); //as returns type IInterfaceA and must be explicitly casted to return ImplementedClass @implementedClass2.Hello(); ImplementedClass @implementedClass3 = @implementedClass as ImplementedClass; //as returns ImplementedClass which can be assigned to type ImplementedClass directly. @implementedClass3.Hello(); }
static void Main(string[] args) { DerivedClass dClass = new DerivedClass(); IInterfaceA dClassUpToA = dClass as IInterfaceA; dClassUpToA.Method(); Console.WriteLine(dClassUpToA.GetHashCode()); IInterfaceB dClassUpToB = new DerivedClass(); dClassUpToB.Method(); Console.WriteLine(dClassUpToB.GetHashCode()); Console.ReadKey(); }
public void ResolvedInstancesAreSameForSingletonWhenResolvedUsingMissingTypeEventWithTag() { const string Tag = "TAG"; var serviceLocator = new ServiceLocator(); serviceLocator.MissingType += (s, e) => { var tagString = (string)e.Tag; IInterfaceA instance = (tagString == Tag) ? new ClassATag() as IInterfaceA : new ClassA() as IInterfaceA; e.ImplementingInstance = instance; e.RegistrationType = RegistrationType.Singleton; }; var classATag = serviceLocator.ResolveType <IInterfaceA>(Tag); var classATag2 = serviceLocator.ResolveType <IInterfaceA>(Tag); Assert.AreSame(classATag, classATag2); }
public void CanResolveSingletonByMissingTypeEventArgsWithTag() { const string Tag = "TAG"; var serviceLocator = new ServiceLocator(); serviceLocator.MissingType += (s, e) => { var tagString = (string)e.Tag; IInterfaceA instance = (tagString == Tag) ? new ClassATag() as IInterfaceA : new ClassA() as IInterfaceA; e.ImplementingInstance = instance; e.RegistrationType = RegistrationType.Singleton; }; var classA = serviceLocator.ResolveType <IInterfaceA>(); var classATag = serviceLocator.ResolveType <IInterfaceA>(Tag); Assert.IsInstanceOf(typeof(ClassA), classA); Assert.IsInstanceOf(typeof(ClassATag), classATag); }
public void CanMixDifferentInterceptionMechanismsForSameContainerConfiguration() { IUnityContainer container = GetContainer("CanMixDifferentInterceptionMechanismsForSameContainerConfiguration"); IInterfaceA abc = container.Resolve <IInterfaceA>(); abc.TargetMethod(); Assert.AreEqual <string>("behaviour2", DoNothingInterceptionBehavior.BehaviourName); HasVirtualMethods abc1 = container.Resolve <HasVirtualMethods>(); abc1.TargetMethod(); Assert.AreEqual <string>("behaviour1", DoNothingInterceptionBehavior.BehaviourName); ImplementsMBRO abc2 = container.Resolve <ImplementsMBRO>(); abc2.TargetMethod(); Assert.AreEqual <string>("behaviour3", DoNothingInterceptionBehavior.BehaviourName); }
public static void Print(this IInterfaceA a) => Console.WriteLine("A");
public void NonExistentBehaviourSpecifiedThrowsValidException() { IUnityContainer container = GetContainer("NonExistentBehaviourSpecifiedThrowsValidException"); IInterfaceA proxy = container.Resolve <IInterfaceA>(); }
internal ConsumeInterface() { _sample = new Sample(); _iInterfaceA = new ExplicitInterfaceImplementation(); }
public ClassB() { pA = (IInterfaceA)Container.Instance.Resolver <IInterfaceA>(); }
public IGraphActionResult FullName(IInterfaceA person) { return(this.Ok($"{person.FirstName} {person.LastName}")); }
public ClassB(IInterfaceA classA) { _classA = classA; }
public QueryObjectWithPrivateCtor(IInterfaceA dependencyA, IInterfaceB dependencyB) { this.dependencyA = dependencyA; this.dependencyB = dependencyB; }
// Elapsed milliseconds about 0.007 // 32B GC public void TestGetInterface() { _interfaceA = _luaTable.Get <IInterfaceA>("interfaceA"); }