473,796 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Dynamic Properties" - no really...

All samples related to this see to come short of being 'truly' dynamic. For
instance, after creating all the code to load/save a properties value, you
turn around and save it to one you KNOW exists:

foo.Height = (my loaded value)...

I am trying to load and set the property on the fly - without necessarily
knowing what it is. Imagine a 100 name/value pairs in a file (config, res,
txt, whatever). I want to load and set those on the fly, without knowing
about the properties that exist (dynamic) or don't (exception handling). For
instance:

MyForm.Controls["myctrlname "]["mypropname "] = myvalue;

....where all three "unknowns" are loaded on the fly. I know C++ couldn't do
this but scripting languages can. Given that this is an intermediate type
language, is this possible?

--
Brad Eck
<a href="http://www.sitesdynami c.com">SitesDyn amic</a>
<a href="http://www.basketsetce tera.com">Baske ts Etcetera</a>
Nov 17 '05 #1
5 1745
Brad,

Yes, this is very easy to do using reflection. Basically, you will get
the Type instance for the instance you want to create. Once you create the
instance, you will get the PropertyInfo for the appropriate property to
get/set. With that, you can then get/set the property on a specific
instance.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Brad" <br******@sites dynamic.com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
All samples related to this see to come short of being 'truly' dynamic.
For
instance, after creating all the code to load/save a properties value, you
turn around and save it to one you KNOW exists:

foo.Height = (my loaded value)...

I am trying to load and set the property on the fly - without necessarily
knowing what it is. Imagine a 100 name/value pairs in a file (config, res,
txt, whatever). I want to load and set those on the fly, without knowing
about the properties that exist (dynamic) or don't (exception handling).
For
instance:

MyForm.Controls["myctrlname "]["mypropname "] = myvalue;

...where all three "unknowns" are loaded on the fly. I know C++ couldn't
do
this but scripting languages can. Given that this is an intermediate type
language, is this possible?

--
Brad Eck
<a href="http://www.sitesdynami c.com">SitesDyn amic</a>
<a href="http://www.basketsetce tera.com">Baske ts Etcetera</a>

Nov 17 '05 #2
Brad <br******@sites dynamic.com> wrote:
All samples related to this see to come short of being 'truly' dynamic. For
instance, after creating all the code to load/save a properties value, you
turn around and save it to one you KNOW exists:

foo.Height = (my loaded value)...

I am trying to load and set the property on the fly - without necessarily
knowing what it is. Imagine a 100 name/value pairs in a file (config, res,
txt, whatever). I want to load and set those on the fly, without knowing
about the properties that exist (dynamic) or don't (exception handling). For
instance:

MyForm.Controls["myctrlname "]["mypropname "] = myvalue;

...where all three "unknowns" are loaded on the fly. I know C++ couldn't do
this but scripting languages can. Given that this is an intermediate type
language, is this possible?


Absolutely. You can use reflection to find the property with the
appropriate name, and then set it to the new value. Which bit are you
having trouble with?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
Hi,

You have two things involved here, one is accesing a property, which would
be "mypropname " , you can access it using reflection like this:

objVar.GetType( ).GetProperty( "mypropname " ).SetValue( objVar, myvalue );
Another thing is accesing a indexed property , in this case is the Controls
collection, in this case you have to use a similar construction as above but
pass the index.

the important thing is that you need to differentiate between both cases. as
they use different set of parameters.Othe r than that I see no problem

OTOH I would bet that you can do the same with managed C++ as this is part
of the framework, you can do it with any .net language

"Brad" <br******@sites dynamic.com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
All samples related to this see to come short of being 'truly' dynamic.
For
instance, after creating all the code to load/save a properties value, you
turn around and save it to one you KNOW exists:

foo.Height = (my loaded value)...

I am trying to load and set the property on the fly - without necessarily
knowing what it is. Imagine a 100 name/value pairs in a file (config, res,
txt, whatever). I want to load and set those on the fly, without knowing
about the properties that exist (dynamic) or don't (exception handling).
For
instance:

MyForm.Controls["myctrlname "]["mypropname "] = myvalue;

...where all three "unknowns" are loaded on the fly. I know C++ couldn't
do
this but scripting languages can. Given that this is an intermediate type
language, is this possible?

--
Brad Eck
<a href="http://www.sitesdynami c.com">SitesDyn amic</a>
<a href="http://www.basketsetce tera.com">Baske ts Etcetera</a>

Nov 17 '05 #4
Hi,

The code below has error, there is no SetValue with that set of parameters,
but it needs an extra one, for handle the indexed properties, with an non
indexed property using null as the third parameter:

objVar.GetType( ).GetProperty( "mypropname " ).SetValue( objVar, myvalue ,
null );

so you use the same method call you just have to pass either null or a
object[] depending if it;s an indexed property or not.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:uM******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

You have two things involved here, one is accesing a property, which
would be "mypropname " , you can access it using reflection like this:

objVar.GetType( ).GetProperty( "mypropname " ).SetValue( objVar,
myvalue );
Another thing is accesing a indexed property , in this case is the
Controls collection, in this case you have to use a similar construction
as above but pass the index.

the important thing is that you need to differentiate between both cases.
as they use different set of parameters.Othe r than that I see no problem

OTOH I would bet that you can do the same with managed C++ as this is part
of the framework, you can do it with any .net language

"Brad" <br******@sites dynamic.com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
All samples related to this see to come short of being 'truly' dynamic.
For
instance, after creating all the code to load/save a properties value,
you
turn around and save it to one you KNOW exists:

foo.Height = (my loaded value)...

I am trying to load and set the property on the fly - without necessarily
knowing what it is. Imagine a 100 name/value pairs in a file (config,
res,
txt, whatever). I want to load and set those on the fly, without knowing
about the properties that exist (dynamic) or don't (exception handling).
For
instance:

MyForm.Controls["myctrlname "]["mypropname "] = myvalue;

...where all three "unknowns" are loaded on the fly. I know C++ couldn't
do
this but scripting languages can. Given that this is an intermediate type
language, is this possible?

--
Brad Eck
<a href="http://www.sitesdynami c.com">SitesDyn amic</a>
<a href="http://www.basketsetce tera.com">Baske ts Etcetera</a>


Nov 17 '05 #5
OK, I am really close but the examples for this that I found are still
showing a couple probs. Most importantly, I do a GetProperty() with the
name and get valid info but when I call InvokeMember() with the GetField
or GetProperty (not sure which to use) it fails as not finding it ???

Type tmpType = currentCtrl.Get Type();
PropertyInfo pi = tmpType.GetProp erty(resource.p ropName);
if (!pi.CanWrite) // writable?
continue;
tmpType.InvokeM ember(resource. propName,
BindingFlags.Se tField, null, currentCtrl,
new object [] {resource.propV alue});

HELP!!!

Brad Eck
http://www.sitesdynamic.com
http://www.basketsetcetera.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #6

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

Similar topics

6
6025
by: Jordi Vilar | last post by:
Hi All, Is there a way to dynamic_cast a pointer to a type defined by a type_info*? something like: type_info *info_of_type_to_cast = typeid(type_to_cast); type_to_cast *casted = really_dynamic_cast<info_of_type_to_cast>(my_data_ptr);
1
1600
by: Razzbar | last post by:
I'm creating a site that is all on one page. The navigation of the site is enabled by a hidden iframe that fetches content from the server and re/places it in a div on the page. The problem is how to allow visitors to bookmark "pages" when the page is dynamic. I can use Apache-style pseudo-urls to parse out the location of the dynamic content, like... http://fakepage.gov/foo/20345583 or...
7
5853
by: GfxGuy | last post by:
I've seen this problem posted a million times, but I've read through all of them and can't figure out what I'm doing wrong. Simple example (this is the whole file, no editing): ---------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>
0
1453
by: raca | last post by:
I am trying to create a generic SOA ServiceInvoker that will accept an XML string that will be used to deserialize an object generated by XSDObjectGen. The hierarchy goes like this: Requests...Request (1..n)... Payload (1)... PayloadCollection (1) ... Payload (0...n) I have the knowledge about the root object Responses which I can create directly. However I don't know what is the type for Request and Payload (These will be versioned...
1
1538
by: Phill. W | last post by:
I have a number of properties on a UserControl that are logically related to one another and do a specific job. What I'd /like/ to do is to have these properties available in the Forms Designer, "grouped" together under a single "sub-heading", in the same way as, for example, the standard Font, Location and Size properties. I've wandered around the Browsable and DesignerSerializationVisibility Attributes but the "nearest" I've got so...
1
4765
by: DiegoMx | last post by:
I'm having a problem with "a:visited" properties overriding "a:hover" ones - here's the relevant part of my CSS: a.barra { position:absolute; top:30px; font-family:century gothic; padding:10px; font-size:12pt; font-weight:bold; color:#4855A9;
3
1767
by: EYIII | last post by:
Is it possible to retrieve the "created by" identity and "modified by" identity for a file (e.g. word doc, .pdf, report, etc) using .NET?
0
943
by: walterbyrd | last post by:
This according to SDTimes: http://www.sdtimes.com/article/story-20071215-13.html They don't specifically mention Python. But, I think Python qualifies as a dynamic language. "1. Dynamic languages are on the rise. We went into 2007 knowing that Ruby would be a popular topic, thanks to Ruby on Rails, and that JavaScript was resurgent, thanks to AJAX-based rich Internet
17
2787
by: David C. Ullrich | last post by:
Having a hard time phrasing this in the form of a question... The other day I saw a thread where someone asked about overrideable properties and nobody offered the advice that properties are Bad. So maybe we've got over that. I suppose properties could have Bad consequences if a user doesn't know they exist and think that a certain property of an object is just an ordinary attribute. But that applies to
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.