internal static void SetValueAtIndex(Object obj, ulong index, Object value){
if (obj is ScriptObject){
if (index < UInt32.MaxValue)
((ScriptObject)obj).SetValueAtIndex((uint)index, value);
else
((ScriptObject)obj).SetMemberValue(index.ToString(CultureInfo.InvariantCulture), value);
return;
}
default_property_case:
if (obj is IList){
IList list = (IList)obj;
if (index < (ulong)list.Count)
list[(int)index] = value;
else
list.Insert((int)index, value);
return;
}
if (obj is Array){
checked{((Array)obj).SetValue(Convert.CoerceT(value, obj.GetType().GetElementType()), (int)index);}
return;
}
Type type = obj.GetType();
if (type.IsCOMObject || obj is IReflect || index > Int32.MaxValue){
LateBinding.SetMemberValue(obj, index.ToString(CultureInfo.InvariantCulture), value);
return;
}
//Assume that the object does not itself have a field/property with numerical name.
//See if the object has a default indexed property, or default property that results in an Array or List and work with that.
MethodInfo setter = JSBinder.GetDefaultPropertyForArrayIndex(type, (int)index, null, true);
if (setter != null){
ParameterInfo[] pars = setter.GetParameters();
if (pars == null || pars.Length == 0){
obj = setter.Invoke(obj, BindingFlags.SuppressChangeType, null, null, null);
goto default_property_case;
}else
setter.Invoke(obj, (BindingFlags)0, JSBinder.ob, new Object[]{(int)index, value}, null);
}
}