[RESOLVED] Passing generic classes as arguments
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Passing generic classes as arguments

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    [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)

  2. #2
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    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
    In theory, there is no difference between theory and paractice; 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

  3. #3
    Join Date
    Dec 2008
    Posts
    2

    Re: Passing generic classes as arguments

    But... That's exactly what I'm looking for! You sir, are a mind reader. Thank you!

  4. #4
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: Passing generic classes as arguments

    Quote Originally Posted by mysignin View Post
    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
    In theory, there is no difference between theory and paractice; 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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center