/// <summary> /// Creates a new instance of the safe property wrapper. /// </summary> /// <param name="propertyInfo">Property to wrap.</param> public SafeProperty(PropertyInfo propertyInfo) { Guard.ArgumentNotNull(propertyInfo, "propertyInfo", "You cannot create a dynamic property for a null value."); this.propertyInfo = propertyInfo; getter = DynamicReflectionManager.CreatePropertyGetter(propertyInfo); setter = DynamicReflectionManager.CreatePropertySetter(propertyInfo); }
/// <summary> /// Creates a new instance of the safe constructor wrapper. /// </summary> /// <param name="constructorInfo">Constructor to wrap.</param> public SafeConstructor(ConstructorInfo constructorInfo) { _constructorInfo = constructorInfo; try { _constructor = DynamicReflectionManager.CreateConstructor(constructorInfo); } catch { _isOptimized = false; } }
/// <summary> /// Creates a new instance of the safe method wrapper. /// </summary> /// <param name="methodInfo">Method to wrap.</param> public SafeMethod(MethodInfo methodInfo) { Guard.ArgumentNotNull(methodInfo, "methodInfo", "You cannot create a dynamic method for a null value."); this.methodInfo = methodInfo; this.Name = methodInfo.Name; ParameterInfo[] infoParams = methodInfo.GetParameters(); int pCount = infoParams.Length; if (pCount > 0 && ((pCount == 1 && infoParams[0].ParameterType.IsArray) || (infoParams[pCount - 1].GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0))) { this.hasFinalArrayParam = true; this.methodParamsLength = pCount; this.finalArrayElementType = infoParams[pCount - 1].ParameterType; } this.method = DynamicReflectionManager.CreateMethod(methodInfo); }