Click here to Skip to main content
15,564,017 members

Comments by coolsanjay (Top 4 by date)

coolsanjay 16-Nov-11 3:46am View    
Right now I have written
if(eachProperty.Name.Equals("products")) // products is List<Product>
IEnumerable<Product> productList = eachProperty.GetValue(this.UIPageAttributes, null) as IEnumerable<Product>;

int idx = 1;

if (productList != null)
foreach (Product eachProduct in productList)

string.Format("{0}:{1}|", product.Name,
product.GetValue(eachProduct, null).ToString())
coolsanjay 16-Nov-11 2:55am View    
SAKryukov, Please help me how to solve List<. comparison problem with propertyType.
if (eachProperty.PropertyType == typeof(List<>))?
coolsanjay 16-Nov-11 2:48am View    
What I wanted to do I will describe now. Lets say we have Employee class with some properties like FirstBName, LastName. Also having one property as Departments which is nothing but List<department>, departments which employee belongs to. Now, I want to return string formatted property name and its corresponding value so instead of hardcoding like string str = "FirstName:" + employee.FirstName i thot to use Reflection and use:
foreach (System.Reflection.PropertyInfo eachProperty in this.EmployeeObject.GetType().GetProperties())


So properties I am able to fetch using
if (eachProperty.PropertyType == typeof(string) && eachProperty.GetValue(this.EmployeeObject, null) != null &&
!string.IsNullOrEmpty(eachProperty.GetValue(this.EmployeeObject, null).ToString()))

But how to check for List<department>?
coolsanjay 21-Jun-11 10:13am View    
Reason for my vote of 5
good one