Iは、以下のインターフェースを有する:で自動鋳造タイプ
public partial class ucDisplayDictionary : UserControl
{
public Type DictionaryName { get; set; }
public IDataAccessor DataAccessor { get; set; }
public ucDisplayDictionary(IDataAccessor accessor)
: this()
{
DataAccessor = accessor;
DictionaryName = accessor.GetType();
}
private void btnEditRecord_Click(object sender, EventArgs e)
{
if (dgvDisplayDictionary.CurrentRow != null)
{
var frmEdit = DataAccessor.ShowAddEditForm();
frmEdit.SetValue(dgvDisplayDictionary.CurrentRow.DataBoundItem);
if (frmEdit.GetForm().ShowDialog() == DialogResult.OK)
{
dgvDisplayDictionary.DataSource = null;
dgvDisplayDictionary.DataSource = ((LanguageDataAccessor)DataAccessor).Collection; // *
}
}
}
:私は、次のコードを有するユーザ制御で
public class LanguageDataAccessor : IDataAccessor
{
public void SaveLanguage(Languages language)
{
LanguagesDAO languages = new LanguagesDAO();
languages.Save(language);
}
// other methods...
}
:このインタフェースを継承
public interface IDataAccessor
{
IList GetAllRecords();
IFormEditor ShowAddEditForm();
}
とクラス文字列(*)そのようなものを書きたい:
dgvDisplayDictionary.DataSource = ((DictionaryName)DataAccessor).Collection;
このユーザーコントロールは、他のDataAccessorのために一般的ですので、
私はこれをどのように行うことができますか?
ありがとう、私の英語のために申し訳ありません。
なぜあなたはちょうどIDataAcccessorにコレクションを追加しないと、すべての鋳造を避けますか? –