Python.Runtime.ArrayObject.mp_ass_subscript C# (CSharp) Метод

mp_ass_subscript() приватный Метод

private mp_ass_subscript ( IntPtr ob, IntPtr idx, IntPtr v ) : int
ob System.IntPtr
idx System.IntPtr
v System.IntPtr
Результат int
	public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) {
	    CLRObject obj = (CLRObject)ManagedType.GetManagedObject(ob);
	    Array items = obj.inst as Array;
	    Type itemType = obj.inst.GetType().GetElementType();
	    int rank = items.Rank;
	    int index = 0;
	    object value;

	    if (items.IsReadOnly) {
		Exceptions.RaiseTypeError("array is read-only");
		return -1;
	    }

	    if (!Converter.ToManaged(v, itemType, out value, true)) {
		return -1;
	    }

	    if (rank == 1) {
		index = (int)Runtime.PyInt_AsLong(idx);

		if (Exceptions.ErrorOccurred()) {
		    Exceptions.RaiseTypeError("invalid index value");
		    return -1;
		}

		if (index < 0) {
		    index = items.Length + index;
		}

		try {
		    items.SetValue(value, index);
		}
		catch (IndexOutOfRangeException) {
		    Exceptions.SetError(Exceptions.IndexError,
					"array index out of range"
					);
		    return -1; 
		}

		return 0;
	    }

	    if (!Runtime.PyTuple_Check(idx)) {
		Exceptions.RaiseTypeError("invalid index value");
		return -1;
	    }

	    int count = Runtime.PyTuple_Size(idx);

	    Array args = Array.CreateInstance(typeof(Int32), count);

	    for (int i = 0; i < count; i++) {
		IntPtr op = Runtime.PyTuple_GetItem(idx, i);
		index = (int)Runtime.PyInt_AsLong(op);

		if (Exceptions.ErrorOccurred()) {
		    Exceptions.RaiseTypeError("invalid index value");
		    return -1;
		}

		if (index < 0) {
		    index = items.GetLength(i) + index;
		}

		args.SetValue(index, i);
	    }

	    try {
		items.SetValue(value, (int[])args);
	    }
	    catch (IndexOutOfRangeException) {
		Exceptions.SetError(Exceptions.IndexError,
				    "array index out of range"
				    );
		return -1;
	    }

	    return 0;
	}