[MonoDevelop] Further regarding being unable to access fields/actions in MainWindow from another class

Michael Hutchinson m.j.hutchinson at gmail.com
Tue Jul 1 01:37:05 EDT 2008


On Tue, Jul 1, 2008 at 12:36 AM, Brett Senior <brett_senior at yahoo.com.au> wrote:
> Dear All,
>
>     Further to the e-mail I sent a couple of weeks ago regarding the need to
> be able to access widget names & actions in the Main Window class from
> another class.  As I mentioned I do it in VS using a 'pointer' to the window
> and then access the fields that I want that way.  I've looked deeper into my
> application and unless I programatically add *all* controls to the window
> (and thus be able to declare them as something other than private) I cannot

What don't you just expose the particular widgets that you need as properties?

public Entry NameEntry { get { return nameEntry; } }

or better, just expose the *functionality* that you need, without
exposing the details of the window:

public string UserName { get { return nameEntry.Text; } set {
nameEntry.Text = value; }}

> convert this application and unfortunately that means I will have to
> maintain Vista/VS.  Is it possible to add this requirement to a list of
> 'desired features' that could be looked into whenever a new release of MD
> occurs ?
>     Note: I also tried changing the 'Build()' code but it seems that this is
> regenerated every time that a compile occurs and thus even though this would
> have been a maintenance issue - I cannot use this method either.  Also I
> feel that having to add all of the controls programatically (and there a a
> *lot* of them) defeats the purpose of a very good tool such as MD.

It's hard to be certain without looking at the particular use case,
but it sounds to me like an design/encapsulation problem. It's
generally considered a bad idea to expose fields directly -- which is
why we have properties. A lot nicer than java/c++ getters and setters
:)

I'm not sure, but I think that just declaring the fields yourself
(with different accessibility) may work.

If there's still a compelling case for changing the accessibility of
fields, please file an enhancement request on bugzilla.

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Monodevelop-list mailing list