-
December 31st, 2008, 01:42 PM
#1
[RESOLVED] Passing generic classes as arguments
I'm unsure of what exactly I'm looking for, so hopefully you'll be able to work through it with me, and someone will be able to tell me what if what I'm talking about exists in .NET.
What I'm trying to accomplish is writing a class that will accept any object along with its properties and values of those properties, and modify the object, setting the properties to those values. What I'm imagining is a method that accepts an object and a dictionary with the objects Properties as keys, and the Values those properties are set to as values. Then the code will set each property to the correct value. Another option would be to call the constructor for that object's class, and pass each property to that, then return the object.
What is important here is that I don't want to have to write a new method or class for each object I may be passing and modifying, and would rather just pass a different dictionary and object.
I don't know what that's called in .NET or C#, I looked up generics, but unless I missed something, I don't think it will be able to do what I want.
If you're interested in the implementation of this class, I'm using it to simplify accessing an SQL database in my webapp. I want to be able to have Add, Get, Modify and Delete methods, so the Modify method will be the one described above. It will accept the object and the Properties/Values, modify the existing object (or create a new one) write it to the database, and return it to the calling code.
If anyone has any code samples, or even keywords about what this technology is called in .NET, I'd be very appreciative!
Thank you!
(I'm using VS 2008 and .NET 3.5)
-
December 31st, 2008, 01:50 PM
#2
Re: Passing generic classes as arguments
One word......REFLECTION.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 31st, 2008, 02:01 PM
#3
Re: Passing generic classes as arguments
But... That's exactly what I'm looking for! You sir, are a mind reader. Thank you!
-
December 31st, 2008, 02:06 PM
#4
Re: Passing generic classes as arguments
Originally Posted by mysignin
But... That's exactly what I'm looking for! You sir, are a mind reader. Thank you!
Being a mind reader is easy..but it is being a mind writer that gives real power....
Glad to help, dont forget to rate those who help (by clicking on the little scales to the right of the post).
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|