Typed Collections in .NET, Silverlight, and Java SDKs
We've recently added a new set of objects to our statically-typed-language SDKs (.Net, Silverlight and Java). These objects are a set of typed collections, aimed at making your client code easier to write and clearer to understand.
Previously, if you were using the getUsers() method, your code would have looked something like this:
In .NET:
RibbitCollectionResponse users = new RibbitUser().getUsers(); UserResource user = (UserResource)users.Results[0];
In Java:
RibbitCollectionResponse users = new Ribbit().users().getUsers(); UserResource user = (UserResource)users.getResults.get(0);
We've added a UserResourceList, which implements List<UserResource> in Java and IList<UserResource> in .NET. This gives you a typed resource straight out of the collection. This means you won't have to cast the resources. Developers can now access the collection elements directly, instead of via the Results property.
So your code will now look something like this:
In .NET:
UserResourceList users = new RibbitUser().getUsers(); UserResource user = users[0];
In Java:
UserResourceList users = new Ribbit().users().getUsers(); UserResource user = users.get(0);
Further, this means that in .NET, the collections can be bound straight to DataGrids.
For example, an ASP.NET data grid showing 4 columns from the UserResource object:
<asp:DataGrid ID="UsersDataGrid" runat="server" AutoGenerateColumns="False" OnItemCommand="GetUsers_Click"> <Columns> <asp:BoundColumn DataField="Id" ReadOnly="True" HeaderText="User ID" /> <asp:BoundColumn DataField="Login" ReadOnly="True" HeaderText="Login" /> <asp:BoundColumn DataField="FirstName" ReadOnly="True" HeaderText="First Name" /> <asp:BoundColumn DataField="LastName" ReadOnly="True" HeaderText="Last Name" /> </Columns> </asp:DataGrid>
We hope this makes your development a little easier.
- gmarcionetti's blog
- Login or register to post comments
-






