Re: create properties at runtime?
- From: "Cowboy \(Gregory A. Beamer\)" <NoSpamMgbworld@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 May 2006 07:30:52 -0500
You end up having to continue to reflect to late bind. If you are using
Visual Basic, you can use the late binding syntax, which makes this a bit
easier; for C#, you are stuck with Reflection to late bind.
There is a risk of a miss when you late bind, however, as a failed
compilation will not be found until you attempt to access. This is when a
good "try" strategy is in order. Do you catch and attempt to create and then
run, or do you simply use finally to clean up and allow errors up the stack?
Eval() would be nice, as the language would have a quick way of testing.
--
Gregory A. Beamer
*************************************************
Think Outside the Box!
*************************************************
"Ben Voigt" <rbv@xxxxxxxxxxxxx> wrote in message
news:uFAytk4fGHA.324@xxxxxxxxxxxxxxxxxxxxxxx
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@xxxxxxxxxxxxxxxxxx> wrote in
message news:%23bMansyfGHA.4004@xxxxxxxxxxxxxxxxxxxxxxx
If you truly want to take a class, or better yet, extend a class at
runtime, you have a couple of options. First is reflection.emit, which
allows you to create and compile a class, in memory, on the fly. You can
also dig into the Code DOM and do the same thing.
I am not sure, however, that creating a class to act as a property bag is
the best option. Simply holding keys in memory, as a DataSet for example,
will serve the same purpose without the infrastructure needed to support
"on demand" classes. Without knowing more about your project, I endorse
neither approach, but, as classes are the more time consuming and complex
route, consider simpler methods before heading that route.
--
Gregory A. Beamer
I definitely agree with Greg. I've recently gone the Reflection.Emit
route, because I was creating 300 classes from XML files which will now
form the object model for additional coding. How will these dynamic
properties be accessed? No code compiled before reading the XML file can
possibly use the new properties. Only if you have some sort of scripting
language (JScript.NET eval for example) would this be helpful, but JScript
already supports extender properties.
For storage and enumeration, a Dictionary is the simplest way to go.
If you are adding properties to scriptable objects, look into the way
JScript.NET and/or IronPython do it.
*************************************************
Think Outside the Box!
*************************************************
"joe" <joe@xxxxxxxxx> wrote in message
news:Oy%2392lxfGHA.2456@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I want to create some sort of engine, that would read some keys from an
xml document
and for each key to create a property for the engine;
Because I want to use one single class with several xml files, I thought
of making strong typed properties
(or at least string properties) at run-time.
Any ideas?
Thank you,
Dan
.
- References:
- create properties at runtime?
- From: joe
- Re: create properties at runtime?
- From: Cowboy \(Gregory A. Beamer\)
- Re: create properties at runtime?
- From: Ben Voigt
- create properties at runtime?
- Prev by Date: Re: Switching to the UI Thread
- Next by Date: Re: Server Application Unavailable
- Previous by thread: Re: create properties at runtime?
- Next by thread: Counting the calls INTO my component?
- Index(es):
Relevant Pages
|