/// <summary> /// Creates the property access item. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="propertyInfo">The property information.</param> /// <returns>The property access item.</returns> internal static PropertyAccessItem CreatePropertyAccessItem(Type objectType, PropertyInfo propertyInfo) { if (objectType == null) { throw new ArgumentNullException("objectType"); } if (propertyInfo == null) { throw new ArgumentNullException("propertyInfo"); } bool canRead = propertyInfo.CanRead; bool canWrite = propertyInfo.CanWrite; PropertyAccessItem propertyAccessItem = new PropertyAccessItem { CanRead = canRead, CanWrite = canWrite }; if (canRead) { propertyAccessItem.Getter = DynamicMethodHelper.EmitPropertyGetter(objectType, propertyInfo); } if (canWrite) { propertyAccessItem.Setter = DynamicMethodHelper.EmitPropertySetter(objectType, propertyInfo); } return(propertyAccessItem); }
/// <summary> /// Calls the static method. /// </summary> /// <param name="type">The type.</param> /// <param name="methodInfo">The method information.</param> /// <param name="parameters">The parameters.</param> /// <returns>The static method return value.</returns> /// <exception cref="System.ArgumentNullException"> /// type /// or /// methodInfo /// </exception> /// <exception cref="ReflectionHelperException"></exception> public static object CallStaticMethod(Type type, MethodInfo methodInfo, params object[] parameters) { if (type == null) { throw new ArgumentNullException("type"); } if (methodInfo == null) { throw new ArgumentNullException("methodInfo"); } if (parameters == null) { parameters = new object[] { null }; } Type[] parameterTypes; CheckParameters(methodInfo, parameters, out parameterTypes); return(s_DynamicMethodCache.GetOrAddDelegate(new DynamicMethodInfo(type, MemberTypes.Method, methodInfo.Name, parameterTypes), () => DynamicMethodHelper.EmitMethodInvoker(type, methodInfo), DynamicMethodCacheStrategy.Temporary)(null, parameters)); }
/// <summary> /// Creates the instance. /// </summary> /// <param name="type">The type.</param> /// <param name="constructorInfo">The constructor information.</param> /// <param name="parameterTypes">The parameter types.</param> /// <param name="parameters">The parameters.</param> /// <returns>The created instance.</returns> /// <exception cref="System.ArgumentNullException"> /// type /// or /// constructorInfo /// </exception> public static object CreateInstance(Type type, ConstructorInfo constructorInfo = null, Type[] parameterTypes = null, params object[] parameters) { if (type == null) { throw new ArgumentNullException("type"); } if (parameterTypes == null) { parameterTypes = Type.EmptyTypes; } if (constructorInfo == null && parameterTypes.Length == 0) { constructorInfo = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); } if (constructorInfo == null) { throw new ArgumentNullException("constructorInfo"); } return(s_DynamicMethodCache.GetOrAddDelegate(new DynamicMethodInfo(type, MemberTypes.Constructor, constructorInfo.Name, parameterTypes), () => DynamicMethodHelper.EmitConstructorInvoker(type, constructorInfo, parameterTypes), DynamicMethodCacheStrategy.Temporary)(parameters)); }