Solved

How to extend/modify a C# object dynamically

Posted on 2009-04-08
4
482 Views
Last Modified: 2012-05-06
I'm looking for a way to allow the users of my C# .NET WinForms application to extend its business domain without having me make manual changes to the VS Project.
Here is an example:
Let's say, we have an application called "Friends List" that helps keep track of one's friends.
In this application there is an object named "Person", which has a single public property "FIrstName".
Now, let's assume that there is a second application called "List Maker" that present the user with a simple form to allow add more properties to the "Person" (i.e. "Last Name", "Address", etc...)
Once such additions are made, the "List Maker" application would, in fact, make changes to the existing "Person" class by adding the "Last Name" and "Address" public properties to it.
Then the "List Maker" application would recompile the "Friends List" project, so, the next time the user run it, the Person will have those added properties.
I think, this could be accomplished with a help of the CSharpCodeProvider class.
I'm just not sure how to do this.

-Eugene
0
Comment
Question by:eugene-g
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 24102169
The way I would do is to have a parent class called person and then provide a child class which inherits from person with additional properties and do all the operations on the child class object
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 24102413
Have a look at the discussion here. It might be helpful:

http://forums.asp.net/t/1362348.aspx
0
 

Author Comment

by:eugene-g
ID: 24107378
Is there a way to compile a C# solution without having Visual Studio installed?
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 24245595
Of course that's possible. Using C# compiler from a command line. Have a look:

http://www.softsteel.co.uk/tutorials/cSharp/lesson18.html

It's also possible to use tools like nant to "build" (compile) your solution. You may search for nant on internet. Have a look at simple example:

http://nant.sourceforge.net/release/latest/help/fundamentals/buildfiles.html
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question