?
Solved

How to extend/modify a C# object dynamically

Posted on 2009-04-08
4
Medium Priority
?
486 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
  • 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 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

862 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