It will be my first question here so please be lenient.
How is this possible:
//there is a Form1 class which has a TableAdapter member generated by designer...
partial class Form1
{
private void InitializeComponent()
{
this.SomeTableTableAdapter = new SomeDatabaseDataSetTableAdapters.SomeTableTableAdapter();
}
private SomeDatabaseDataSetTableAdapters.SomeTableTableAdapter SomeTableTableAdapter;
}
//here is this TableAdapter class
//It has PROTECTED member called "Adapter"
public partial class SomeTableTableAdapter : global::System.ComponentModel.Component
{
protected internal global::System.Data.SqlClient.SqlDataAdapter Adapter
{
}
}
//and in the constructor of Form1 class I can do something like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.SomeTableTableAdapter.Adapter.InsertCommand.CommandText = @"INSERT INTO (...)";
}
}
How come I get access to protected member since Form1 do not inherit from SomeTableTableAdapter?
protected internal
means protected OR internal. Access is allowed either from derived classes or from the containing assembly.Access Modifiers (C# Programming Guide):
The
Adapter
property is declared asprotected internal
, which means it is accessible to derived classes (protected
) and to classes in the same assembly (internal
). SinceForm1
is in the same assembly asSomeTableTableAdapter
, they can access each other's internal members.