public static void SetIndexedPropertyValueStatic(Object obj, Object[] arguments, Object value){
if (obj == null)
throw new JScriptException(JSError.ObjectExpected);
ScriptObject scrob = obj as ScriptObject;
if (scrob != null){
scrob[arguments] = value;
return;
}
Array arr = obj as Array;
if (arr != null){
if (arguments.Length != arr.Rank)
throw new JScriptException(JSError.IncorrectNumberOfIndices);
arr.SetValue(value, LateBinding.ToIndices(arguments));
return;
}
TypeCode tcode = Convert.GetTypeCode(obj);
if (Convert.NeedsWrapper(tcode)) return; //senseless assignment to implicit wrapper. Do nothing.
IReflect ir = LateBinding.GetIRForObjectThatRequiresInvokeMember(obj, true, tcode); //Either called from IL, or on an type object
if (ir != null){
//Legacy behavior is to convert the last argument to a string and treat it as the name of the property being set
String name = String.Empty;
int n = arguments.Length;
if (n > 0)
name = Convert.ToString(arguments[n-1]);
const BindingFlags flags =
BindingFlags.Public|BindingFlags.Instance|BindingFlags.OptionalParamBinding|
BindingFlags.SetProperty|BindingFlags.SetField;
ir.InvokeMember(name, flags, JSBinder.ob, obj, new Object[]{value}, null, null, null);
return;
}
MemberInfo[] defaultMembers = TypeReflector.GetTypeReflectorFor(obj.GetType()).GetDefaultMembers();
if (defaultMembers != null && defaultMembers.Length > 0){
PropertyInfo prop = JSBinder.SelectProperty(Runtime.TypeRefs, defaultMembers, arguments);
if (prop != null){
MethodInfo setter = JSProperty.GetSetMethod(prop, false);
if (setter != null){
arguments = LateBinding.LickArgumentsIntoShape(prop.GetIndexParameters(), arguments, JSBinder.ob, null);
value = Convert.CoerceT(value, prop.PropertyType);
int n = arguments.Length + 1;
Object[] newargs = new Object[n];
ArrayObject.Copy(arguments, 0, newargs, 0, n-1);
newargs[n-1] = value;
setter.Invoke(obj, newargs);
return;
}
}
}
throw new JScriptException(JSError.OLENoPropOrMethod);
}