C# How to create various objects at runtime that can hold strongly typed data?
Posted
by JL
on Stack Overflow
See other posts from Stack Overflow
or by JL
Published on 2010-05-14T12:22:01Z
Indexed on
2010/05/14
12:24 UTC
Read the original article
Hit count: 207
c#
Is it possible to create objects at runtime without having to have hard coded class definitions, then populate properties with primitives or even strongly typed data types?
For example:
Lets say I want to an XML config file that could hold configuration values for connecting to various systems in an SOA application. In C# I read in these values, but for each system the properties are different (e.g: SQL might have a connection string, while SharePoint might need a username + password + domain + url, while yet an smtp server would need username + password + port + url)
So instead of creating static classes as follows
public class SharePointConfiguration or public class SQLConfiguration, then have each class with custom properties (this is cumbersome)
Is there not a more preferred way to achieve this, without using 1990's methods, in otherwords it would still be nice to have intellisense and code completion and named properties.
Since this collection of properties (object) would be passed within the class and possible to other classes from function to function I am also wondering where this class definition would get defined if its all happening at run time.
Any recommendations, and hope the question was clear enough. Would like to use language features, not hacks. Thank you.
© Stack Overflow or respective owner