Solved

How to extend/modify a C# object dynamically

Posted on 2009-04-08
4
478 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
Comment Utility
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
Comment Utility
Have a look at the discussion here. It might be helpful:

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

Author Comment

by:eugene-g
Comment Utility
Is there a way to compile a C# solution without having Visual Studio installed?
0
 
LVL 29

Expert Comment

by:anarki_jimbel
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now