Main Site Documentation

Some magic within Gadgeteer.Program sources


#1

Sometimes ago I decided than I don’t need to inherit from Gadgeteer.Program class for my application’s entry point so I had replaced it with my own realization.
But the topic is not about that. Actually it about some strange thing that still not very clear for me.

Lets open a source codes of Gadgeteer.Program class.
This class have a following property:

protected internal static Mainboard Mainboard
        {
            get
            {
                if (_Mainboard == null) throw new Exception("Program instance must be constructed before Mainboard or any module is used (use a template)");
                return _Mainboard;
            }
            protected set
            {
                if (_Mainboard != null) throw new Exception("Mainboard cannot be initialised twice");
                Module.Mainboard = _Mainboard = value;
                Debug.Print("Using mainboard " + Mainboard.MainboardName + " version " + Mainboard.MainboardVersion);
            }
        }

Take a look at line


Static property Module.Mainboard initialized with value.
But Module.Mainboard property is declared as protected!

```cs
 public abstract partial class Module
    {
        /// <summary>
        /// Gets a reference to the Mainboard API used by the current Gadgeteer Program.
        /// </summary>
        protected internal static Mainboard Mainboard;
}

So how it is possible to set protected property from another class?


#2

@ Sergey Bokhantsev - It is actually declared protected internal. Protected internal members can be accessed from both derived classes just like protected (even those outside of the assembly) and from anywhere within the same assembly just like internal. See http://msdn.microsoft.com/en-us/library/ms173121.aspx


#3

:think:
Didn’t know that…
I’m confused why I didn’t noticed ‘internal’ keyword in a Module.Mainboard definition.