We help IT Professionals succeed at work.

Getting at a value

paulwhelan
paulwhelan asked
on
Medium Priority
199 Views
Last Modified: 2010-04-16
Hi
I want to get at a value in an instantiation of a class.

Im using Visual Studio 2005

When in debug mode I hover over the variable oControl and it says

oControl {DefaultControlsPlugin.Contols.ElementLabelControl}

then I hit the + beside that and it shows me certain values

_oGuid
_oOwner
etc

However the value I want is under
[DefaultControlsPlugin.Controls.ElementLabelControl]

And I click on + again and its in there as _sText

When I go to the HTML visualizer for this value it says

((DefaultControlsPlugin.Controls.ElementLabelControl)(oControl))._sText

But how do I print this out in my code?

I can do

myvalue = oControl.ToString();

but that sets myvalue to be
DefaultControlsPlugin.Controls.ElementLabelControl

Thanks
Paul

Comment
Watch Question

Senior Systems and Integration Developer
CERTIFIED EXPERT
Commented:
You probably can't access it directly because, judging by the name, it is either private or protected. You could probably get to it using reflection, but that is a bit more complex.

Have you tried accessing the value using something like:

    string s = ((DefaultControlsPlugin.Controls.ElementLabelControl)(oControl))._sText

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
nice one - that worked!

Any ideas why? =)

Cheers
Paul
Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
Well.... _sText must be public. So by using:

    ((DefaultControlsPlugin.Controls.ElementLabelControl)(oControl))

You are casting oControl to the correct type, before trying to access the _sText member
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.