In-Line Props

I am working on a brownbag for entity framework using Northwind as my database. When coding up a POCO, I decided to use the in-line property setting available since VS2008:

Product product = new Product()
{
    ProductId = (Int32)sqlDataReader[0],
    ProductName = (String)sqlDataReader[1],
    Supplier = new Supplier(),
    Category = new Category(),
    QuantityPerUnit = (String)sqlDataReader[4],
    UnitPrice = (Int16)sqlDataReader[5],
    UnitsInStock = (Int16)sqlDataReader[6],
    UnitsOnOrder = (Int16)sqlDataReader[7],
    ReorderLevel = (Int16)sqlDataReader[8],
    Discontinued = (Boolean)sqlDataReader[9]
};

The problem is that when I ran it, one of the properties was cast incorrectly. However, by using in-line, I can’t tell which one is the problem.

clip_image002

If I did it the OFW (Old-Fashion Way) like this":

Product product = new Product();
product.ProductId = (Int32)sqlDataReader[0];
product.ProductName = (String)sqlDataReader[1];
product.Supplier = new Supplier();
product.Category = new Category();
product.QuantityPerUnit = (String)sqlDataReader[4];
product.UnitPrice = (Decimal)sqlDataReader[5];
product.UnitsInStock = (Int16)sqlDataReader[6];
product.UnitsOnOrder = (Int16)sqlDataReader[7];
product.ReorderLevel = (Int16)sqlDataReader[8];
product.Discontinued = (Boolean)sqlDataReader[9];

I would have had the break on 1 line and easily identified the offending line of code:

clip_image004

The morale of the story is the same as many of my other stories – separate – don’t be lazy.

One Response to In-Line Props

  1. Rob Seder says:

    I’ll try to help you spread that new acronym “OFW”, I like it! I mean to think, people used to spell stuff out, but that was the OFW! Haha!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: