User Profile
Collapse
-
Thanks again!... -
Right. I'm just trying to see if I can dynamically create the properties, so in the end I have one expandoobject per row in this table with one property for each field in that row with the same name as the column populated with the value in the datarow.
So in the end instead of _Item.c.descrip , I want to have _Item.descrip and the value of item.descrip would equal the value of r["descrip"]. Then in the future if the descrip column...Leave a comment:
-
Thanks, but that isn't exactly what I'm trying to do.
For example, there is a DataColumn called descrip of type string in the DataTable. I want to create _Item.descrip and populate with the text value of the current r.descrip without explicitly declaring _Item.descrip. Can I do that?...Leave a comment:
-
Expando object - adding dynamic properties
Not sure if this is possible or not but I'd like to have an ExpandoObject (.Net 4.0) that I can add properties to without knowing the property name until runtime. I have tried a couple of things but have had no luck yet. Can I do this? Here's a failed attempt:
Code:dynamic _Item = new ExpandoObject(); foreach (DataRow r in dtIT.Rows) { //assign
-
How to dynamically set type
I'm populating object properties from a datatable and sometimes I will need to cast to a type that will not be known until runtime. I tried the following:
Code:foreach (DataRow r in dtIT.Rows) { foreach (PropertyInfo p in t.GetProperties()) { Type pType = p.GetType(); //assign any matching
-
-
Wow, you guys are quick! Thanks for the replies.
Code:if (r[p.Name].GetType == p.GetType)
Error 1 Operator '==' cannot be applied to operands of type 'method group' and 'method group' C:\Users\mburt\ Documents\Visua l Studio 2010\Projects\e Commerce\EComm_ DAL\Classes\Ite mTreeData.cs 61 33 DAL
Code:if (r[p.Name].GetType == typeof(p))
Leave a comment:
-
Reflection, objects, and comparing types
Hi, I'm a vb.net developer getting the hang of c# and I've gotten stuck on trying to compare types. In the following block, I'm populating an object from a DataTable. The table's data types aren't always the right type so as I loop through I want to compare types and optionally try to convert to make the data match the object property types.
Code:Type t = _Item.GetType(); foreach (DataRow r
No activity results to display
Show More
Leave a comment: