D
David Young
I'm using hashtables to transport data between layers in my app, but in so
doing, it seems almost impossible to avoid unboxing.
private static BusinessObject PackageBusinessObject(Hashtable myHashtable)
{
if(myHashtable!=null)
{
BusinessObject myBusinessObject = new BusinessObject();
myBusinessObject.Property1 = (string)myHashtable["Property1"];
myBusinessObject.Property2 = (int)myHashtable["Property2"];
myBusinessObject.Property3 = (DateTime)myHashtable["Property3"];
return myBusinessObject;
}
else
{
return null;
}
}
Obviously, we have to convert the object to a specific type, or else we'll
throw an exception.
Is the answer to use Convert?
ie:
myBusinessObject.Property1 = myHashtable["Property1"].ToString();
myBusinessObject.Property2 = Convert.ToInt32(myHashtable["Property2"]);
myBusinessObject.Property3 = Convert.ToDateTime(myHashtable["Property3"]);
Or does this unbox the object as well?
Dave
doing, it seems almost impossible to avoid unboxing.
private static BusinessObject PackageBusinessObject(Hashtable myHashtable)
{
if(myHashtable!=null)
{
BusinessObject myBusinessObject = new BusinessObject();
myBusinessObject.Property1 = (string)myHashtable["Property1"];
myBusinessObject.Property2 = (int)myHashtable["Property2"];
myBusinessObject.Property3 = (DateTime)myHashtable["Property3"];
return myBusinessObject;
}
else
{
return null;
}
}
Obviously, we have to convert the object to a specific type, or else we'll
throw an exception.
Is the answer to use Convert?
ie:
myBusinessObject.Property1 = myHashtable["Property1"].ToString();
myBusinessObject.Property2 = Convert.ToInt32(myHashtable["Property2"]);
myBusinessObject.Property3 = Convert.ToDateTime(myHashtable["Property3"]);
Or does this unbox the object as well?
Dave