Add attribute reading/writing with basetype checking

Targets #628.