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); } }
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; }
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; }
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); }
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); }
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); }
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) { }
public void OnBaz(IBaz baz) { }
public Foo(IBar bar, IBaz baz) { }
public Bar3(IBaz baz) { this.Baz = baz; }
public Bar(IBaz baz) { Baz = baz; }
public Foo(IBar bar, IBaz baz) { this._bar = bar; this._baz = baz; }
public Task HandleExceptionAsync(ExceptionContext context, IBaz baz) { baz.Set(); return(Task.CompletedTask); }
public FakeHostedService(IFoo foo, IBar bar, IBaz baz) { Debug.Assert(foo != null); Debug.Assert(bar != null); Debug.Assert(baz != null); }
public void OnBaz (IBaz baz) { }
private static void Parameters(IFoo foo, IBar bar, IBaz baz) { }
public Qux(IBar bar, IBaz baz) { }
public ClassWithInterfaceAsField(IBaz ibaz) { this.ibaz = ibaz; }
public HomeController(IHostApplicationLifetime lifetime, IFoo foo, IBar bar1, IBar bar2, IBaz baz1, IBaz baz2) => _lifetime = lifetime;
public Gux(IFoo foo, IBar bar, IBaz baz) { this.Foo = foo; this.Bar = bar; this.Baz = baz; }
public BazRecursive(IBaz baz) { }
public SomeFooDependantClass(Foo foo, int age, IBaz baz) { ConstructorSatisfiedFoo = foo; ConstructorSatisfiedAge = age; ConstructorSatisfiedIBaz = baz; }
public Qux(IBaz baz) { }