15,997,597 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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...