Skip to content

Instantly share code, notes, and snippets.

@cz75hiro
Created September 23, 2010 11:08
Show Gist options
  • Save cz75hiro/593478 to your computer and use it in GitHub Desktop.
Save cz75hiro/593478 to your computer and use it in GitHub Desktop.
Genericの間違えた使い方
interface IData //データインターフェース
{
}
public abstract class SchemaBase//DBスキーマ抽象クラス
{
public SchemaBase() { }
}
public abstract class DAOBase<TSchema, TData>//DAOパターン抽象クラス
where TSchema : SchemaBase
where TData : IData
{
public DAOBase() { }
}
public abstract class ControlerBase//データコントローラー抽象クラス
{
public void Create<TDao, TSchema, TData>()
where TDao : DAOBase<TSchema, TData>
where TSchema : SchemaBase
where TData : IData
{
//各パタメータクラスのインスタンス生成
}
}
class ControlerA : ControlerBase
{
}
class ControlerB : ControlerBase
{
}
class Program
{
static void Main(string[] args)
{
var a = new ControlerA();
var b = new ControlerB();
var list = new List<ControlerBase>();
list.Add(a);
list.Add(b);
a.Create<daoA, schemaA, dataA>(); //foreachできない・・・
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment