Click here to Skip to main content
15,879,535 members

Comments by Member 3919049 (Top 2 by date)

Member 3919049 2-Feb-11 16:02pm View    
Hi John - Maybe I am using this generic method incorrectly.

The T represents a config class and the model is a domain object to be saved. So T and the model parameter represent 2 different things.

The T class stores a mapping of Model property names to database column names so my Repository knows which columns of the underlying database table the model property values should be set to when a database saved is performed.

The T class can be dynamically instantiated because all of the config information is populated within its constructor.

Is this a legitimate use of a generic method? If so then please let me know if dynamic instantiation is possible here and the best way to do it. Thanks!
Member 3919049 2-Feb-11 15:05pm View    
Thanks John - Your code above isn't going to work as-is in my method in the way my method is defined above. If I copy and paste your code into my method above the compiler returns the following error:

The name 'obj' does not exist in the current context

Are you suggesting that I pass in an instance of the BaseConfig implementor as a method parameter instead of just the type spec?

I would rather not require the client to pass in an instance of the BaseConfig implementor if I can dynamically instantiate one in this method based on the T type...