Milos Solution Platform (External Blog)

The Milos Solution Platform is .NET's premier platform for building business applications. This blog is meant for developers who use or evaluate Milos. This blog is used to share tidbits of information provided by the Milos developers at EPS. Many of the posts put the spotlight on new features. We generally recommend that all Milos users (developers) at least scan this blog to keep up with the Milos news.

Content Area Footer

Saturday, December 20, 2008
Object casting convenience methods

This upcoming version of Milos has a nice little enhancement in the utilities namespace. The DataHelper class now has extension methods that make it very convenient to cast from object types (such as fields in DataSets) to their real types.

These helper methods are implemented as extension methods. To use them, you have to add this line of code at the top of your program:

using EPS.Utilities;

Now, the extension methods are automatically available on all objects. For instance, you can do the following:

DataSet myDs = this.GetSomeDataSet(); // Assume that we somehow get a DataSet
DataRow row = myDs.Tables[0].Rows[0];
Guid myGuid = row["id"].ToGuidSafe();
string myString = row["name"].ToStringSafe().Trim();
int myInt = row["number"].ToIntegerSafe();

The main advantage here is that these methods always return valid values, even if the cast object is not valid. For instance, these methods are aware of System.DBNull and they also trap errors.

There are a number of different such methods, including the ability to cast to booleans, DateTime, decimal, and so forth (all common value types, basically).

Posted @ 2:03 PM by Egger, Markus ( -
Comments (18)








Syndication RSS 2.0 RSS 2.0

All My Blogs:
My personal blogs:
Dev and Publishing Dev and Publishing
Travel and Internat. Living Travel and Internat. Living
Other blogs I contribute to:
Milos Blog (US) Milos Blog (US)
VFPConv. Dev Blog (US) VFPConv. Dev Blog (US)
VFPConv. Dev Blog (DE) VFPConv. Dev Blog (DE)


Blog Archives
All Blog Posts

    November (1)
    July (2)
    February (2)
    January (1)
    December (1)
    October (3)
    June (1)
    April (3)
    February (1)
    January (1)
    December (1)
    October (2)
    September (2)
    July (1)
    June (2)
    May (4)
    April (6)
    March (8)
    February (3)
    January (2)
    December (2)
    November (2)




This Blog is powered by MilosTM Collaboration Components.