User Profile

Collapse

Profile Sidebar

Collapse
mattb123
mattb123
Last Activity: Dec 6 '10, 07:27 PM
Joined: May 18 '10
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Thanks again!...
    See more | Go to post

    Leave a comment:


  • 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...
    See more | Go to post

    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?...
    See more | Go to post

    Leave a comment:


  • mattb123
    started a topic Expando object - adding dynamic properties

    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
    ...
    See more | Go to post

  • mattb123
    started a topic How to dynamically set type

    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
    ...
    See more | Go to post
    Last edited by Niheel; May 21 '10, 02:00 AM. Reason: removed non relevant details

  • mattb123
    replied to Reflection, objects, and comparing types
    Looks like that was it! Thank you SO MUCH!
    See more | Go to post

    Leave a comment:


  • mattb123
    replied to Reflection, objects, and comparing types
    Wow, you guys are quick! Thanks for the replies.

    Code:
    if (r[p.Name].GetType == p.GetType)
    Results in the following error in the IDE (won't build):
    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))
    In the above the p...
    See more | Go to post

    Leave a comment:


  • mattb123
    started a topic Reflection, objects, and comparing types

    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
    ...
    See more | Go to post
No activity results to display
Show More
Working...