public void SetUp()
        {
            objectRepository = new Dictionary <string, object>();

            ReflectionOptimizer.Enable();

            var apiCtx = BuildRoutine.Context()
                         .AsClientApplication(
                codingStyle = BuildRoutine.CodingStyle()
                              .FromBasic()
                              .AddCommonSystemTypes()
                              .AddTypes(GetType().Assembly, t => t.Namespace?.StartsWith("Routine.Test.Performance.Domain") == true)

                              .Use(p => p.ParseableValueTypePattern())

                              .Initializers.Add(c => c.PublicConstructors().When(type.of <BusinessPerformanceInput>()))
                              .Datas.Add(c => c.Properties(m => !m.IsInherited(true, true)))
                              .DataFetchedEagerly.Set(true)
                              .Operations.Add(c => c.Methods(o => !o.IsInherited(true, true)))
                              .IdExtractor.Set(c => c.IdByProperty(m => m.Returns <int>("Id")))
                              .Locator.Set(c => c.Locator(l => l.SingleBy(id => objectRepository[id])))
                              .ValueExtractor.Set(c => c.Value(e => e.By(o => $"{o}")))
                );

            objectService = apiCtx.ObjectService;
            rapp          = apiCtx.Application;

            var _ = objectService.ApplicationModel;
        }
        public override void SetUp()
        {
            base.SetUp();

            ReflectionOptimizer.Enable();

            mock = new Mock <IOptimizedInterface <string> >();

            target = new OptimizedClass(mock.Object);
        }
        public void ReflectionCore_PropertyAccess()
        {
            const int load = 100000;

            Console.WriteLine("Load -> " + load);

            Console.WriteLine("-------");
            var obj = new BusinessPerformance {
                Id = 1
            };

            Run("Direct Access", () =>
            {
                var _ = obj.Id;
            }, load);

            Console.WriteLine("-------");

            var prop = obj.GetType().GetProperty("Id");

            Run("System.Reflection Cached Access", () =>
            {
                var _ = prop?.GetValue(obj, Array.Empty <object>());
            }, load);
            ReflectionOptimizer.Disable();
            var rprop1 = obj.GetTypeInfo().GetProperty("Id");

            Run("Routine.Core.Reflection Cached Access (without optimizer) ", () =>
            {
                var _ = rprop1.GetValue(obj);
            }, load);
            ReflectionOptimizer.Enable();
            var rprop2 = obj.GetTypeInfo().GetProperty("Id");

            Run("Routine.Core.Reflection Cached Access", () =>
            {
                var _ = rprop2.GetValue(obj);
            }, load);
            Console.WriteLine("-------");

            Run("System.Reflection Access", () =>
            {
                var _ = obj.GetType().GetProperty("Id")?.GetValue(obj, Array.Empty <object>());
            }, load);
            ReflectionOptimizer.Disable();
            Run("Routine.Core.Reflection Access (without optimizer)", () =>
            {
                var _ = obj.GetTypeInfo().GetProperty("Id").GetValue(obj);
            }, load);
            ReflectionOptimizer.Enable();
            Run("Routine.Core.Reflection Access", () =>
            {
                var _ = obj.GetTypeInfo().GetProperty("Id").GetValue(obj);
            }, load);

            Console.WriteLine("-------");

            Run("Routine.Core.Reflection Access -> GetTypeInfo()", () =>
            {
                var _ = obj.GetTypeInfo();
            }, load);
            var type = obj.GetTypeInfo();

            Run("Routine.Core.Reflection Access -> GetProperty('Id')", () =>
            {
                var _ = type.GetProperty("Id");
            }, load);
            var rprop3 = type.GetProperty("Id");

            Run("Routine.Core.Reflection Access -> GetValue(obj)", () =>
            {
                var _ = rprop3.GetValue(obj);
            }, load);
        }
Esempio n. 4
0
        public static IApplicationBuilder UseRoutineInProductionMode(this IApplicationBuilder source)
        {
            ReflectionOptimizer.Enable();

            return(source);
        }