[Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

How do I access Castle Activerecord class property by index?

Given an activerecord class as follows:

    [ActiveRecord(Table = "`MailMember`",Lazy=true)]
    public class MailMember : BaseObject<MailMember>

        Campaigns campaign;
        public virtual Campaigns Campaign
            get { return campaign; }
            set { campaign = value; }
        string firstName;
        public virtual string FirstName
            get { return firstName; }
            set { firstName = value; }
        string lastName;
        public virtual string LastName
            get { return lastName; }
            set { lastName = value; }

If I create an instance of MailMember:

Mailmember mm = new MailMember();

How can I acess the properties (column names) without knowing the names?

I can access the value by:
string membername = mm.FirstName;

but I want to iterate through all fields in MailMember and create a temporary table using the column names from the mm class, then add a few extra columns:
so I need to be able to get at the property names like mm[1].name (would be 'FirstName')

so I'm thinking something like

DataColumn dc = new DataColumn(mm[1].name.tostring());

or maybe there's another way of using the mailmember instance to create a new Datatable directly, and just add the extra columns to that?

1 Solution
mimpactAuthor Commented:
I thought that might be the answer - thanks for the confirmation

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now