473,378 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Adding a property at runtime

Udi
Hi All,
I have an object that is reflected at runtime by Windows script host
engine,
so its public methods and properties can then be used from within a
script.

Based on a certain condition, I need to allocate a new member inside
that object
to be able to use it through the script engine as well. (This local
member is null and ignored by default)

I was thinking about adding a property that exposes this internal
member at runtime,
so the script engine will be able to see this property while
reflecting my object.

Do you know how can I extend my class and add a new propety to it at
runtime?
Can you show me an example?
Thanks!
Udi.

Aug 1 '07 #1
3 13796
On Aug 1, 10:35 am, Udi <UdiBenSen...@gmail.comwrote:

<snip>
Do you know how can I extend my class and add a new propety to it at
runtime?
Can you show me an example?
You can't. You could use CodeDom to emit a new class derived from the
old one but including the extra property, but that's about as close as
you can get, I believe.

Jon

Aug 1 '07 #2
I have an object that is reflected at runtime by Windows script host
engine,
so its public methods and properties can then be used from within a
script.

Based on a certain condition, I need to allocate a new member inside
that object
to be able to use it through the script engine as well. (This local
member is null and ignored by default)

I was thinking about adding a property that exposes this internal
member at runtime,
so the script engine will be able to see this property while
reflecting my object.

Do you know how can I extend my class and add a new propety to it at
runtime?
Can you show me an example?
Take a look at "ICustomTypeDescriptor" (which you'll inherit your class
from, requiring you to implement "GetProperties()") or in .NET 2.0 and
later, take a look at the "TypeDescriptionProviderAttribute" instead (which
requires you to roll your own "TypeDescriptionProvider" derivative,
overriding "GetTypeDescriptor()" and implementing "GetProperties()" on the
returned "ICustomTypeDescriptor" - also see class "CustomTypeDescriptor"
which you'll want to rely on here). You'll have to research the details of
course but brace yourself. It's very difficult the first time you try it.
There's also another way using the "TypeConverterAttribute" but you probably
don't need that.
Aug 1 '07 #3
Udi,

Why not just add the property to your class, and then check your
condition before you access the property?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Udi" <Ud**********@gmail.comwrote in message
news:11********************@w3g2000hsg.googlegroup s.com...
Hi All,
I have an object that is reflected at runtime by Windows script host
engine,
so its public methods and properties can then be used from within a
script.

Based on a certain condition, I need to allocate a new member inside
that object
to be able to use it through the script engine as well. (This local
member is null and ignored by default)

I was thinking about adding a property that exposes this internal
member at runtime,
so the script engine will be able to see this property while
reflecting my object.

Do you know how can I extend my class and add a new propety to it at
runtime?
Can you show me an example?
Thanks!
Udi.

Aug 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris | last post by:
Dear all, I would like to figure out a way to add controls to a form using specs stored in a table. Any assistance in fleshing this idea out would be greatly appreciated. I'm using VB6. ...
6
by: Terry | last post by:
I have a very basic program, but for some reason I can't get it to behave properly. What I want is a basic form with a TabControl that fills the entire form. The tab control should have 4 tabs...
4
by: slylos | last post by:
I've got a Windows form that has a TabControl. I add TabPages to this TabControl at Runtime, along with two Textboxes and a button. The problem I'm having is I can't figure out how to reference...
2
by: Jaster | last post by:
Hi. i got some trouble including Managed C++. Refering to: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcmg_overview.asp. There is no "Compile As Managed"...
4
by: MattB | last post by:
Hello. I'm creating a page to edit a person's record (name address, etc) using a DataGrid. I want the fields that can be edited to be created at runtime based on a list of columns in web.config....
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
0
by: sonic | last post by:
I am trying to dynamically load a validator and must be missing something elementary here. I extended TextBox control to add some functionality to it. One new feature it contains is IsRequired...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
5
by: florin | last post by:
hi Is there a "simple" way to add attributes to a class/property at runtime? What I try to do is set the default editor for a class/property at runtime (I know I can set this very easy by...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.