Link to home
Start Free TrialLog in
Avatar of Meps
MepsFlag for United States of America

asked on

Dynamic Generic Data Transfer Object

This has to already exist, but I just can't find it, or don't understand what I am looking at.

Simplely put I want to do this.  I want to have an object that I can use that would be generic, but dynamic at the same time.

The code snippet shows something like what I want to do.  I want to create an object, tell it why datatypes I am going to use along with the names of the properties I want, and then be able to fill out the object with the values I want.  So I can pass it along through the application.

So how would I create this generic DTO?
GenDTO bob = new GenDTO();

bob.add(datetime "StartDate");
bob.add(string "Name");

bob.StartDate = '1/1/2010';
bob.Name = 'Smith';

GenDTO g123 = new GenDTO();
g123.add(int "ID");
g123.add(bool "Terminated");

g123.ID = 2;
g123.Terminated = true;

Open in new window

Avatar of jamesrh
jamesrh
Flag of United States of America image

The most standard way to do this is through a dynamically defined DataTable oject.
Avatar of Meps

ASKER

I don't understand, do you happen to have some example code of how I would create the class?
ASKER CERTIFIED SOLUTION
Avatar of Kusala Wijayasena
Kusala Wijayasena
Flag of Sri Lanka image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Meps

ASKER

Thanks