Python.Runtime.FieldObject.tp_descr_set C# (CSharp) Method

tp_descr_set() private method

private tp_descr_set ( IntPtr ds, IntPtr ob, IntPtr val ) : int
ds System.IntPtr
ob System.IntPtr
val System.IntPtr
return int
	public static new int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val) {
	    FieldObject self = (FieldObject)GetManagedObject(ds);
	    Object newval;

	    if (self == null) {
		return -1;
	    }

	    if (val == IntPtr.Zero) {
		Exceptions.SetError(Exceptions.TypeError, 
			            "cannot delete field"
				    );
		return -1;
	    }

	    FieldInfo info = self.info;

	    if (info.IsLiteral || info.IsInitOnly) {
		Exceptions.SetError(Exceptions.TypeError, 
				    "field is read-only"
				    );
		return -1;
	    }

	    bool is_static = info.IsStatic;

	    if ((ob == IntPtr.Zero) || (ob == Runtime.PyNone)) {
		if (!is_static) {
		    Exceptions.SetError(Exceptions.TypeError, 
			       "instance attribute must be set " + 
			       "through a class instance"
			       );
		    return -1;
		}
	    }

	    if (!Converter.ToManaged(val, info.FieldType, out newval, 
				      true)) {
		return -1;
	    }

	    try {
		if (!is_static) {
		    CLRObject co = (CLRObject)GetManagedObject(ob);
		    info.SetValue(co.inst, newval);
		}
		else {
		    info.SetValue(null, newval);
		}
		return 0;
	    }
	    catch(Exception e) {
		Exceptions.SetError(Exceptions.TypeError, e.Message);
		return -1;
	    }
	}