/// <summary> /// Sets the value of the indexer matching <paramref name="bindingFlags"/> of the given <paramref name="obj"/> /// </summary> /// <param name="obj">The object whose indexer is to be set.</param> /// <param name="parameterTypes">The types of the indexer parameters (must be in the right order), plus /// the type of the indexer.</param> /// <param name="bindingFlags">The binding flags used to lookup the indexer.</param> /// <param name="parameters">The list of the indexer parameters plus the value to be set to the indexer. /// This list must match with the <paramref name="parameterTypes"/> list.</param> /// <returns>The object whose indexer is to be set.</returns> /// <example> /// If the indexer is of type <c>string</c> and accepts one parameter of type <c>int</c>, this /// method should be invoked as follow: /// <code> /// obj.SetIndexer(new Type[]{typeof(int), typeof(string)}, new object[]{1, "a"}); /// </code> /// </example> public static object SetIndexer(this object obj, Type[] parameterTypes, Flags bindingFlags, params object[] parameters) { DelegateForSetIndexer(obj.GetTypeAdjusted(), bindingFlags, parameterTypes)(obj, parameters); return(obj); }
/// <summary> /// Sets the value of the indexer of the given <paramref name="obj"/> /// </summary> /// <param name="obj">The object whose indexer is to be set.</param> /// <param name="parameters">The list of the indexer parameters plus the value to be set to the indexer. /// The parameter types are determined from these parameters, therefore no parameter can be <c>null</c>. /// If any parameter is <c>null</c> (or you can't be sure of that, i.e. receive from a variable), /// use a different overload of this method.</param> /// <returns>The object whose indexer is to be set.</returns> /// <example> /// If the indexer is of type <c>string</c> and accepts one parameter of type <c>int</c>, this /// method should be invoked as follow: /// <code> /// obj.SetIndexer(new Type[]{typeof(int), typeof(string)}, new object[]{1, "a"}); /// </code> /// </example> public static object SetIndexer(this object obj, params object[] parameters) { DelegateForSetIndexer(obj.GetTypeAdjusted(), parameters.ToTypeArray())(obj, parameters); return(obj); }