keithwarren7
keithwarren7

Reputation: 14280

MonoTouch [Outlet]s scoping

When I create an outlet in Xcode, MonoTouch creates identical properties in the *.designer.cs file for that particular view.

namespace MyApp
{
    [Register ("CustomCell")]
    partial class CustomCell
    {
        [Outlet]
        MonoTouch.UIKit.UISwitch Toggle { get; set; }

        void ReleaseDesignerOutlets ()
        {
            if (Toggle != null) {
                Toggle.Dispose ();
                Toggle = null;
            }
        }
    }
}

but as you can see, scopes those properties as private.

Is there a way through XCode or MonoTouch to tell the system these should be generated as public, protected or internal?

Granted I could expose properties in the implementation side of this partial class that act as proxies to these properties but I am hoping there is a cleaner way.

Upvotes: 0

Views: 226

Answers (2)

Mikayla Hutchinson
Mikayla Hutchinson

Reputation: 16153

Don't worry that they're properties, this is an implementation detail of outlets. You can think of them as private fields - so it's fine to expose them via more accessible properties on the non-designer class part.

Another way to make them more accessible is to move them to the non-designer class part. Outlets don't have to be in the designer class part.

How syncing works:

The way the designer files work is that when MD syncs to Xcode, it finds all outlets on all parts of the class, including the designer class, and syncs those into the obj-c header file. When it syncs the obj-c header file back to MD, it tries to find each of the outlets in the non-designer class parts, then regenerates the designer file with the unmatched outlets.

This means that if you add an outlet in obj-c header file, it will get added into the designer file. It also means that if you remove an outlet in the obj-c header file, it will effectvely get removed from the designer file when the designer file is regenerated - unless it's in some other class part, in which case the removal will not be synced.

The outlets in the obj-c header file do not have any accessibility, so MD cannot sync that when it regenerates the header file, and private is a good default since it promotes encapsulation, and you can easily expose them if needed via wrapper properties or by moving them.

Upvotes: 2

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

There is currently no way to make MonoDevelop generate different visibility attributes for outlets exposed.

What is the use case scenario that you have in mind?

Upvotes: 0

Related Questions