public async Task <long> TestReflection(int mode, int numberOfObjects) { List <MyClass> myClassList = Enumerable.Repeat(new MyClass(), numberOfObjects).ToList(); IObjectReflection cache = null; if (mode == 1) { cache = ObjectReflectionService.GetInstace(typeof(MyClass), typeof(DefaultObjectReflectionProvider <>)); } else if (mode == 2) { cache = ObjectReflectionService.GetInstace(typeof(MyClass), typeof(DelegateObjectReflectionProvider <>)); } object aux = 0; var stopwatch = new Stopwatch(); foreach (var obj in myClassList) { switch (mode) { case 1: case 2: stopwatch.Start(); aux = cache.GetProperty(obj, "Test0"); cache.ConvertSetProperty(obj, "Test0", 123); aux = cache.GetProperty(obj, "Test1"); cache.ConvertSetProperty(obj, "Test1", "123"); aux = cache.GetProperty(obj, "Test2"); cache.ConvertSetProperty(obj, "Test2", "123"); aux = cache.GetProperty(obj, "Test3"); cache.ConvertSetProperty(obj, "Test3", "2019-04-16"); aux = cache.GetProperty(obj, "Test4"); cache.ConvertSetProperty(obj, "Test4", "9EA9C2BA-CF59-46EB-BE4D-E6002DFBCD3B"); stopwatch.Stop(); break; default: stopwatch.Start(); aux = obj.Test0; obj.Test0 = (string)ConvertTo(123, typeof(string)); aux = obj.Test1; obj.Test1 = (int)ConvertTo("123", typeof(int)); aux = obj.Test2; obj.Test2 = (decimal)ConvertTo("123", typeof(decimal)); aux = obj.Test3; obj.Test3 = (DateTime)ConvertTo("2019-04-16", typeof(DateTime)); aux = obj.Test4; obj.Test4 = (Guid)ConvertTo("9EA9C2BA-CF59-46EB-BE4D-E6002DFBCD3B", typeof(Guid)); stopwatch.Stop(); break; } } stopwatch.Stop(); return(stopwatch.ElapsedTicks); }
public void CacheReflection() { ObjectReflectionService.GetInstace(typeof(MyClass), typeof(DelegateObjectReflectionProvider <>)); ObjectReflectionService.GetInstace(typeof(MyClass), typeof(DefaultObjectReflectionProvider <>)); }