コード例 #1
0
        public void BuidUnkownCtorWithParams_CanBuildAnonymousConstructor_BuildsConstructorThatCanParseStringsToValueTypes()
        {
            var now  = DateTime.Now;
            var anon = new
            {
                Property1 = default(long?),
                Property2 = default(long),
                Property3 = default(DateTime?),
                Property4 = default(DateTime),
                Property5 = default(string),
                Property6 = default(SomeEnum),
                Property7 = default(SomeEnum?)
            };

            var ctor = DelegateBuilder.BuildUnknownCtorWithParams(anon.GetType().GetConstructors().First());

            var instance = ctor((long?)1, (long)2, now, now, "str", SomeEnum.Value1, SomeEnum.Value2);

            instance.PropertyValue <long?>("Property1").Should().Be.EqualTo(1);
            instance.PropertyValue <long>("Property2").Should().Be.EqualTo(2);
            instance.PropertyValue <DateTime?>("Property3").Should().Be.EqualTo(now);
            instance.PropertyValue <DateTime>("Property4").Should().Be.EqualTo(now);
            instance.PropertyValue <string>("Property5").Should().Be.EqualTo("str");
            instance.PropertyValue <SomeEnum>("Property6").Should().Be.EqualTo(SomeEnum.Value1);
            instance.PropertyValue <SomeEnum?>("Property7").Should().Be.EqualTo(SomeEnum.Value2);
        }
コード例 #2
0
        public void DelegateBuilderNewParameters_Speed()
        {
            Speed  inst  = null;
            long   seven = 7;
            double eight = 8;
            float  nine  = 9;
            var    ctor  = DelegateBuilder.BuildUnknownCtorWithParams(typeof(Speed).GetConstructors().First(x => x.GetParameters().Length > 0));
            var    watch = Stopwatch.StartNew();

            for (int i = 0; i < Iterations; i++)
            {
                inst = (Speed)ctor("1", 2, 3m, new byte[0], "5", 6, seven, eight, nine, Speed.SpeedEnum.None);
            }
            watch.Stop();
            Trace.WriteLine(inst.Property1);
            Trace.WriteLine(watch.ElapsedMilliseconds);
        }