Solved

How to extend/modify a C# object dynamically

Posted on 2009-04-08
4
481 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 29

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 29

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

837 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