Avatar of Meps
Meps
Flag 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

ASP.NETC#Visual Basic.NET

Avatar of undefined
Last Comment
Meps

8/22/2022 - Mon
jamesrh

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

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

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Meps

ASKER
Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy