private static BusinessPerformance NewObj(int id, int subObjectCount) { var result = new BusinessPerformance { Id = id }; for (var i = 0; i < subObjectCount; i++) { result.Items.Add(new BusinessPerformanceSub { Id = id * (subObjectCount + 1) + i, Prop1 = i + "_prop1", Prop2 = i + "_prop2", Prop3 = i + "_prop3", Prop4 = i + "_prop4", Prop5 = i + "_prop5", Prop6 = i + "_prop6", Prop7 = i + "_prop7", Prop8 = i + "_prop8", Prop9 = i + "_prop9", Prop10 = i + "_prop10", }); } return(result); }
protected void AddToRepository(BusinessPerformance obj) { objectRepository.Add(codingStyle.GetIdExtractor(obj.GetTypeInfo()).GetId(obj), obj); foreach (var sub in obj.Items) { objectRepository.Add(codingStyle.GetIdExtractor(sub.GetTypeInfo()).GetId(sub), sub); } }
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); }