예제 #1
0
        public Bar(IBaz baz)
        {
            if (baz == null)
                throw new ArgumentNullException("baz");

            this.Baz = baz;
        }
        public void StaticPropertyGetter1WorksWithBoxing()
        {
            var property = typeof(Garply).GetProperty(nameof(Garply.Baz));

            var getter = new StaticPropertyGetter <IBaz>(property);

            getter.Func.Target.Should().BeSameAs(getter);
            getter.Func.Method.Name.Should().Be(nameof(getter.GetValueReflection));
            getter.Func.Method.DeclaringType.Should().Be(typeof(StaticPropertyGetter <IBaz>));

            var  reflectionTimer = Stopwatch.StartNew();
            IBaz reflectionValue = getter.GetValue();

            reflectionTimer.Stop();

            getter.SetOptimizedFunc();

            getter.Func.Target.Should().NotBeSameAs(getter);
            getter.Func.Method.Name.Should().Be(StaticPropertyGetter.GetStaticValueOptimized);
            getter.Func.Method.DeclaringType.Should().NotBe(typeof(StaticPropertyGetter <IBaz>));

            var  optimizedTimer = Stopwatch.StartNew();
            IBaz optimizedValue = getter.GetValue();

            optimizedTimer.Stop();

            optimizedValue.Should().Be(reflectionValue);
            optimizedTimer.Elapsed.Should().BeLessThan(reflectionTimer.Elapsed);
        }
        public void PropertyGetter2WorksWithBoxing()
        {
            var bar = new Bar {
                Baz = new Baz(123)
            };
            var property = typeof(Bar).GetProperty(nameof(Bar.Baz));

            var getter = new PropertyGetter <Bar, IBaz>(property);

            getter.Func.Target.Should().BeSameAs(getter);
            getter.Func.Method.Name.Should().Be(nameof(getter.GetValueReflection));
            getter.Func.Method.DeclaringType.Should().Be(typeof(PropertyGetter <Bar, IBaz>));

            var  reflectionTimer = Stopwatch.StartNew();
            IBaz reflectionValue = getter.GetValue(bar);

            reflectionTimer.Stop();

            getter.SetOptimizedFunc();

            getter.Func.Target.Should().NotBeSameAs(getter);
            getter.Func.Method.Name.Should().Be(PropertyGetter.GetValueOptimized);
            getter.Func.Method.DeclaringType.Should().NotBe(typeof(PropertyGetter <Bar, IBaz>));

            var  optimizedTimer = Stopwatch.StartNew();
            IBaz optimizedValue = getter.GetValue(bar);

            optimizedTimer.Stop();

            optimizedValue.Should().Be(reflectionValue);
            optimizedTimer.Elapsed.Should().BeLessThan(reflectionTimer.Elapsed);
        }
        public void FieldGetter2WorksWithBoxing()
        {
            var bar = new Bar {
                Baz = new Baz(123)
            };
            var field = typeof(Bar).GetField(nameof(Bar.Baz));

            var getter = new FieldGetter <Bar, IBaz>(field !);

            getter.Func.Target.Should().BeSameAs(getter);
            getter.Func.Method.Name.Should().Be(nameof(getter.GetValueReflection));
            getter.Func.Method.DeclaringType.Should().Be(typeof(FieldGetter <Bar, IBaz>));

            using (var gc = new GCNoRegion(4194304))
            {
                var  reflectionTimer = Stopwatch.StartNew();
                IBaz reflectionValue = getter.GetValue(bar);
                reflectionTimer.Stop();

                getter.SetOptimizedFunc();

                getter.Func.Target.Should().NotBeSameAs(getter);
                getter.Func.Method.Name.Should().Be(FieldGetter.GetValueOptimized);
                getter.Func.Method.DeclaringType.Should().NotBe(typeof(FieldGetter <Bar, IBaz>));

                var  optimizedTimer = Stopwatch.StartNew();
                IBaz optimizedValue = getter.GetValue(bar);
                optimizedTimer.Stop();

                optimizedValue.Should().Be(reflectionValue);
                optimizedTimer.Elapsed.Should().BeLessThan(reflectionTimer.Elapsed);
            }
        }
예제 #5
0
        public static int Main(String[] args)
        {
            int ret = 0;

            Console.WriteLine("CLR Remoting Sample: Custom Proxy");

            Type[] types = new Type[2];
            types[0] = typeof(IFaq);
            types[1] = typeof(IBaz);

            Console.WriteLine("Generate a new MyProxy using the Type");

            MyProxy myProxy = new MyProxy(typeof(MarshalByRefObject), types);

            Console.WriteLine("Obtain the transparent proxy from myProxy");
            MarshalByRefObject mbr = (MarshalByRefObject)myProxy.GetTransparentProxy();

            IFaq faq = (IFaq)mbr;
            int  r   = faq.MethodX(5, "hi");

            Console.WriteLine("{0}", r);

            IBaz baz = (IBaz)faq;
            int  r2  = baz.MethodY(123.45);

            Console.WriteLine("{0}", r);

            Console.WriteLine("Sample Done");
            return(ret);
        }
        public void StaticFieldGetter1WorksWithBoxing()
        {
            var field = typeof(Garply).GetField(nameof(Garply.Baz));

            var getter = new StaticFieldGetter <IBaz>(field !);

            getter.Func.Target.Should().BeSameAs(getter);
            getter.Func.Method.Name.Should().Be(nameof(getter.GetValueReflection));
            getter.Func.Method.DeclaringType.Should().Be(typeof(StaticFieldGetter <IBaz>));

            using (var gc = new GCNoRegion(4194304))
            {
                var  reflectionTimer = Stopwatch.StartNew();
                IBaz reflectionValue = getter.GetValue();
                reflectionTimer.Stop();

                getter.SetOptimizedFunc();

                getter.Func.Target.Should().NotBeSameAs(getter);
                getter.Func.Method.Name.Should().Be(StaticFieldGetter.GetStaticValueOptimized);
                getter.Func.Method.DeclaringType.Should().NotBe(typeof(StaticFieldGetter <IBaz>));

                var  optimizedTimer = Stopwatch.StartNew();
                IBaz optimizedValue = getter.GetValue();
                optimizedTimer.Stop();

                optimizedValue.Should().Be(reflectionValue);
                optimizedTimer.Elapsed.Should().BeLessThan(reflectionTimer.Elapsed);
            }
        }
 public Plugin3([NotNull] IBar bar, [CanBeNull] IBaz baz = null)
 {
     if (bar == null)
     {
         throw new ArgumentNullException("bar");
     }
     this.Bar = bar;;
     this.Baz = baz;
 }
예제 #8
0
        public Foo(IBar bar, IBaz baz)
        {
            if (bar == null)
                throw new ArgumentException("bar");

            if (baz == null)
                throw new ArgumentNullException("baz");

            this.Bar = bar;
            this.Baz = baz;
        }
예제 #9
0
 public void Configure(IApplicationBuilder app, IFoo foo, IBar bar, IBaz baz)
 {
     app.Run(async context =>
     {
         var response         = context.Response;
         response.ContentType = "text/html";
         await response.WriteAsync($"foo: {foo}<br/>");
         await response.WriteAsync($"bar: {bar}<br/>");
         await response.WriteAsync($"baz: {baz}<br/>");
     });
 }
        public void RegisterInterfaceInstance()
        {
            SimpleContainer c = new SimpleContainer();

            IBaz baz1 = new Baz();

            c.RegisterInstance <IBaz>(baz1);

            IBaz baz2 = c.Resolve <IBaz>();

            Assert.AreEqual(baz2, baz1);
        }
 public Plugin2([NotNull] IBar bar, [NotNull] IBaz baz)
 {
     if (bar == null)
     {
         throw new ArgumentNullException("bar");
     }
     if (baz == null)
     {
         throw new ArgumentNullException("baz");
     }
     this.Bar = bar;
     this.Baz = baz;
 }
        public void RegisterInstanceAfterType()
        {
            SimpleContainer c = new SimpleContainer();

            c.RegisterType <IBaz, Baz>(true);
            IBaz baz1 = c.Resolve <IBaz>();

            IBaz baz2 = new Baz();

            c.RegisterInstance <IBaz>(baz2);

            IBaz baz3 = c.Resolve <IBaz>();

            Assert.AreNotEqual(baz2, baz1);
            Assert.AreEqual(baz3, baz2);
        }
예제 #13
0
        public void MixedConstruction()
        {
            Container.Register <IFoo>(() => new Foo());
            Container.Register <IBar>(typeof(Bar));
            Container.Register <IBaz>(typeof(Baz));

            IBaz instance = Container.Resolve <IBaz>();

            // Test that the correct types were created
            Assert.IsInstanceOfType(instance, typeof(Baz));

            var baz = instance as Baz;

            Assert.IsInstanceOfType(baz.Bar, typeof(Bar));
            Assert.IsInstanceOfType(baz.Foo, typeof(Foo));
        }
        public void RegisterTypeSingletonAfterInstance()
        {
            SimpleContainer c = new SimpleContainer();

            IBaz baz1 = new Baz();

            c.RegisterInstance <IBaz>(baz1);

            c.RegisterType <IBaz, Baz>(true);

            IBaz baz2 = c.Resolve <IBaz>();
            IBaz baz3 = c.Resolve <IBaz>();

            Assert.IsInstanceOfType(baz2, typeof(Baz));
            Assert.AreNotEqual(baz2, baz1);
            Assert.AreEqual(baz3, baz2);
        }
예제 #15
0
        public void MixedConstruction()
        {
            var container = new DiContainer();

            container.Register <IFoo>(() => new Foo());
            container.Register <IBar>(typeof(Bar));
            container.Register <IBaz>(typeof(Baz));

            IBaz instance = container.Resolve <IBaz>();

            // Test that the correct types were created
            Assert.IsInstanceOf(typeof(Baz), instance);

            var baz = instance as Baz;

            Assert.IsInstanceOf(typeof(Bar), baz.Bar);
            Assert.IsInstanceOf(typeof(Foo), baz.Foo);
        }
예제 #16
0
        public void InheritanceTest()
        {
            object  something = new FooB();
            FooBase foo       = GoInterface <FooBase> .From(something);

            Assert.That(foo.Foo() == "Foo");
            Assert.That(foo.Bar() == "Bar");
            Assert.That(foo.Baz(1) == "Baz");
            Assert.That(((IBaz)foo).Baz(false) == "Baz");
            Assert.That(foo.Baz() == "Baz");

            something = new FooB();
            IBaz baz = GoInterface <IBaz> .ForceFrom(something);

            Assert.That(((IBar)baz).Bar() == "Bar");
            Assert.That(((IBar2)baz).Bar() == "Bar");
            Assert.That(baz.Baz() == "Baz");
        }
        public void DisposableImplementationsAreDisposed()
        {
            IConfigurationRoot configuration = GetConfig();

            IBaz baz = configuration.GetSection("baz").CreateReloadingProxy <IBaz>();

            Baz initialBaz = (Baz)((ConfigReloadingProxy <IBaz>)baz).Object;

            Assert.False(initialBaz.IsDisposed);

            ChangeConfig(configuration);

            Baz changedBaz = (Baz)((ConfigReloadingProxy <IBaz>)baz).Object;

            Assert.False(changedBaz.IsDisposed);
            Assert.True(initialBaz.IsDisposed);

            ((IDisposable)baz).Dispose();

            Assert.True(changedBaz.IsDisposed);
        }
 public Bar2(IBaz baz)
 {
 }
예제 #19
0
 public void OnBaz(IBaz baz)
 {
 }
예제 #20
0
 public Foo(IBar bar, IBaz baz)
 {
 }
예제 #21
0
 public Bar3(IBaz baz)
 {
     this.Baz = baz;
 }
예제 #22
0
 public Bar(IBaz baz)
 {
     Baz = baz;
 }
 public Foo(IBar bar, IBaz baz)
 {
     this._bar = bar;
     this._baz = baz;
 }
예제 #24
0
 public Task HandleExceptionAsync(ExceptionContext context, IBaz baz)
 {
     baz.Set();
     return(Task.CompletedTask);
 }
예제 #25
0
 public Foo(IBar bar, IBaz baz)
 {
     this._bar = bar;
     this._baz = baz;
 }
 public FakeHostedService(IFoo foo, IBar bar, IBaz baz)
 {
     Debug.Assert(foo != null);
     Debug.Assert(bar != null);
     Debug.Assert(baz != null);
 }
예제 #27
0
	public void OnBaz (IBaz baz)
	{
	}
예제 #28
0
 public Foo(IBar bar, IBaz baz)
 {
 }
예제 #29
0
 private static void Parameters(IFoo foo, IBar bar, IBaz baz)
 {
 }
 private static void Parameters(IFoo foo, IBar bar, IBaz baz) { }
예제 #31
0
 public Qux(IBar bar, IBaz baz)
 {
 }
예제 #32
0
 public ClassWithInterfaceAsField(IBaz ibaz)
 {
     this.ibaz = ibaz;
 }
예제 #33
0
 public HomeController(IHostApplicationLifetime lifetime, IFoo foo, IBar bar1, IBar bar2, IBaz baz1, IBaz baz2)
 => _lifetime = lifetime;
예제 #34
0
 public Gux(IFoo foo, IBar bar, IBaz baz)
 {
     this.Foo = foo;
     this.Bar = bar;
     this.Baz = baz;
 }
예제 #35
0
 public BazRecursive(IBaz baz)
 {
 }
 public SomeFooDependantClass(Foo foo, int age, IBaz baz)
 {
     ConstructorSatisfiedFoo  = foo;
     ConstructorSatisfiedAge  = age;
     ConstructorSatisfiedIBaz = baz;
 }
예제 #37
0
파일: Qux.cs 프로젝트: vgaltes/IoCTesting
 public Qux(IBaz baz)
 {
 }