Dynamic String to object

Feb 22 2006 6:08 PM

Hi,

I have written a function to return the value stored in an object class. The function takes 2 parameters.

  1. An array element position
  2. Name of the property whose value needs to be returned.

What I am not able to do is to concatenate the string and convert it in object, so that the value can be returned. here is the code.

public

String GetSessionOrderValue(String LineId, String strPropertyVal)

{

String retVal = "";

if (HttpContext.Current.Session["OrderDetails"] != null)

{

 String strLineId = LineId;

PaBasket BasketOrder = new PaBasket();

BasketOrder = (PaBasket)HttpContext.Current.Session["OrderDetails"];

foreach (PaBasket.BasketDet p1 in BasketOrder)

{

if (p1.BLineId == strLineId)

{

retVal = p1+@"."+strPropertyVal;

break;

}

}

}

return retVal;

}

The text I have made red is where I am am not able to construct a valid object as for e.g. p1.Baddress would return the value (address) stored in the object.

I want to make this function a common one, so that I can call it from different pages, instaed of repeating this code on every page.

How can I achieve this?

Thanks in advance,