set complex property on the fly

set complex property on the fly

am 03.12.2005 21:49:38 von George Meng

Hi folks,



I have a Treeview control in the Winform, and I want to change the text of
the 5th node base on an expression:



dim sObject as string = "Treeview1.Node.Items(5).Text"

dim sValue as string = "New Text for the node"



How can I make this happen by using reflection or any other way?



Basically, my question is how I can make change to a complex property:

Object.Property.property



Thanks for any ideas.



George

Re: set complex property on the fly

am 04.12.2005 02:59:44 von vimakefile

You'll need to:
(1) parse your expression string, then use the System.Reflection API to get
the values of each sub-property in turn.
or
(2) Comple the expression and load the resulting assembly (requires compiler
installed)
or
(3) Choose a scripting language that can handle your expression, and ask it
to evaluate your expression. (Try IronPython- that should work for you.)

m


"George Meng" wrote in message
news:e5U5MsE%23FHA.2616@TK2MSFTNGP15.phx.gbl...
> Hi folks,
>
>
>
> I have a Treeview control in the Winform, and I want to change the text of
> the 5th node base on an expression:
>
>
>
> dim sObject as string = "Treeview1.Node.Items(5).Text"
>
> dim sValue as string = "New Text for the node"
>
>
>
> How can I make this happen by using reflection or any other way?
>
>
>
> Basically, my question is how I can make change to a complex property:
>
> Object.Property.property
>
>
>
> Thanks for any ideas.
>
>
>
> George
>
>

Re: set complex property on the fly

am 04.12.2005 03:06:04 von vimakefile

"Mike" wrote in message
news:ez90mZH%23FHA.2324@TK2MSFTNGP11.phx.gbl...
>
> You'll need to:
> (1) parse your expression string, then use the System.Reflection API to
> get the values of each sub-property in turn.
> or
> (2) Comple the expression and load the resulting assembly (requires
> compiler installed)

or
(2a) Parse your expression string, and use Reflection.Emit to generate code
on the fly, and load the assembly. (I didn't mention this before, as it's
the hardest and probably won't by you much over (1) unless you call the same
expression over and over many times

> or
> (3) Choose a scripting language that can handle your expression, and ask
> it to evaluate your expression. (Try IronPython- that should work for
> you.)
>
> m
>
>
> "George Meng" wrote in message
> news:e5U5MsE%23FHA.2616@TK2MSFTNGP15.phx.gbl...
>> Hi folks,
>>
>>
>>
>> I have a Treeview control in the Winform, and I want to change the text
>> of the 5th node base on an expression:
>>
>>
>>
>> dim sObject as string = "Treeview1.Node.Items(5).Text"
>>
>> dim sValue as string = "New Text for the node"
>>
>>
>>
>> How can I make this happen by using reflection or any other way?
>>
>>
>>
>> Basically, my question is how I can make change to a complex property:
>>
>> Object.Property.property
>>
>>
>>
>> Thanks for any ideas.
>>
>>
>>
>> George
>>
>>
>
>

Re: set complex property on the fly

am 04.12.2005 14:45:38 von George Meng

Thanks Mike, your suggestions are very helpful. I prefer to use reflection
to do it.
I will try.

"Mike" дÈëÏûÏ¢ÐÂÎÅ:uxfRJdH%23FHA.160@TK2MSFTNGP12.phx.gbl...
>
> "Mike" wrote in message
> news:ez90mZH%23FHA.2324@TK2MSFTNGP11.phx.gbl...
>>
>> You'll need to:
>> (1) parse your expression string, then use the System.Reflection API to
>> get the values of each sub-property in turn.
>> or
>> (2) Comple the expression and load the resulting assembly (requires
>> compiler installed)
>
> or
> (2a) Parse your expression string, and use Reflection.Emit to generate
> code on the fly, and load the assembly. (I didn't mention this before, as
> it's the hardest and probably won't by you much over (1) unless you call
> the same expression over and over many times
>
>> or
>> (3) Choose a scripting language that can handle your expression, and ask
>> it to evaluate your expression. (Try IronPython- that should work for
>> you.)
>>
>> m
>>
>>
>> "George Meng" wrote in message
>> news:e5U5MsE%23FHA.2616@TK2MSFTNGP15.phx.gbl...
>>> Hi folks,
>>>
>>>
>>>
>>> I have a Treeview control in the Winform, and I want to change the text
>>> of the 5th node base on an expression:
>>>
>>>
>>>
>>> dim sObject as string = "Treeview1.Node.Items(5).Text"
>>>
>>> dim sValue as string = "New Text for the node"
>>>
>>>
>>>
>>> How can I make this happen by using reflection or any other way?
>>>
>>>
>>>
>>> Basically, my question is how I can make change to a complex property:
>>>
>>> Object.Property.property
>>>
>>>
>>>
>>> Thanks for any ideas.
>>>
>>>
>>>
>>> George
>>>
>>>
>>
>>
>
>