Пример #1
0
        public void PerformanceTests()
        {
            int    n = 10000000;
            object x = null;

            // tesla.PlaceOfBirth
            start = DateTime.Now;
            for (int i = 0; i < n; i++)
            {
                x = tesla.PlaceOfBirth;
            }
            stop = DateTime.Now;
            PrintTest("tesla.PlaceOfBirth (direct)", n, Elapsed);

            start = DateTime.Now;
            IDynamicProperty placeOfBirth = DynamicProperty.Create(typeof(Inventor).GetProperty("PlaceOfBirth"));

            for (int i = 0; i < n; i++)
            {
                x = placeOfBirth.GetValue(tesla);
            }
            stop = DateTime.Now;
            PrintTest("tesla.PlaceOfBirth (dynamic reflection)", n, Elapsed);

            start = DateTime.Now;
            PropertyInfo placeOfBirthPi = typeof(Inventor).GetProperty("PlaceOfBirth");

            for (int i = 0; i < n; i++)
            {
                x = placeOfBirthPi.GetValue(tesla, null);
            }
            stop = DateTime.Now;
            PrintTest("tesla.PlaceOfBirth (standard reflection)", n, Elapsed);
        }
Пример #2
0
        /// <summary>
        /// Creates a new instance of the safe property wrapper.
        /// </summary>
        /// <param name="property">Property to wrap.</param>
        public SafeProperty(PropertyInfo property)
        {
            this.propertyInfo = property;

            if (property.CanRead &&
                property.GetGetMethod() != null &&
                ReflectionUtils.IsTypeVisible(property.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME))
            {
                dynamicProperty = DynamicProperty.Create(property);
                isOptimizedGet  = true;
            }

            canSet = property.CanWrite && !(propertyInfo.DeclaringType.IsValueType && !propertyInfo.GetSetMethod(true).IsStatic);
            if (property.GetSetMethod() != null &&
                ReflectionUtils.IsTypeVisible(property.DeclaringType, DynamicReflectionManager.ASSEMBLY_NAME))
            {
                if (dynamicProperty == null)
                {
                    dynamicProperty = DynamicProperty.Create(property);
                }
                isOptimizedSet = true;
            }
        }
 protected override IDynamicProperty Create(PropertyInfo property)
 {
     return(DynamicProperty.Create(property));
 }