这将是我的第一个问题,因此请宽容。
这怎么可能:
//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 (...)";
}
}
由于Form1不继承自SomeTableTableAdapter,我如何获得对 protected 成员的访问权限?
最佳答案
Adapter
属性声明为protected internal
,这意味着派生类(protected
)和可以访问同一程序集(internal
)中的类。由于Form1
与SomeTableTableAdapter
在同一程序集中,因此它们可以访问彼此的内部成员。