Some magic within Gadgeteer.Program sources

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?

@ 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 Access Modifiers - C# Programming Guide | Microsoft Learn

2 Likes

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