Re: create properties at runtime?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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







.



Relevant Pages

  • -k bindings for Gnome - gconf-editor to the rescue. (Re: Key bindings)
    ... Now i'm trying to bind "Lock screen" to LeftWinkey + ... I wanted to bind keys modified with ... Shortcuts dialog doesn't work right. ... In the Sawfish window manager, ...
    (Ubuntu)
  • Re: IP Problems
    ... Does anyone know what this command, route delete default, did? ... I found the bouncer would not bind to the IP 66.246.xx.185 as ... a normal account user and the bouncer would not function. ...
    (freebsd-questions)
  • ssh_exchange_identification: Connection closed by remote host
    ... works except SSH. ... Bind to port 22 on 0.0.0.0 failed: ... I have probably re-create keys. ...
    (comp.security.ssh)
  • Re: are Catholics Christians ?!
    ... Have I to take it Jesus passed the Keys ... to you then and whatever YOU bind and loose on here will be bound and loosed ... God bless, ...
    (uk.religion.christian)
  • Re: Disabling most bindings
    ... for numeric keys. ... the entry widget provides the -validate option family (- ... all the bindings from Entry except for, ... bind NumEntry $binding ...
    (comp.lang.tcl)