code_junkie

interface type method parameter implementation c#

Nov 11th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. interface IDBBase {
  2.  
  3. DataTable getDataTableSql(DataTable curTable,IDbCommand cmd);
  4. ...
  5. }
  6.  
  7. class DBBase : IDBBase {
  8.  
  9. public DataTable getDataTableSql(DataTable curTable, SqlCommand cmd) {
  10. ...
  11. }
  12. }
  13.  
  14. class DBBase : IDBBase {
  15.  
  16. DataTable IDBBase.getDataTableSql(DataTable curTable, IDbCommand cmd) {
  17. return getDataTableSql(curTable, (SqlCommand)cmd); // of course you should do some type checks
  18. }
  19.  
  20. public DataTable getDataTableSql(DataTable curTable, SqlCommand cmd) {
  21. ...
  22. }
  23. }
  24.  
  25. interface IDBClass<T> where T:IDbCommand
  26. {
  27. void Test(T cmd);
  28. }
  29.  
  30. class DBClass:IDBClass<SqlCommand>
  31. {
  32. public void Test(SqlCommand cmd)
  33. {
  34. }
  35. }
  36.  
  37. interface Interface1 { }
  38. class Class1 : Interface1 {}
  39.  
  40. interface Interface2 { void Foo(Interface1 i1);}
  41. class Class2 : Interface2 {void Foo(Class1 c1) {}}
  42.  
  43. interface Interface2 { void Foo(Interface1 i1);}
  44. class Class2 {void Foo(Class1 c1) {}}
  45.  
  46. interface Interface2 { void Foo(Interface1 i1);}
  47. class Class2:Interface2 {void Foo(Class1 c1) {}}
  48.  
  49. genClass"<"typeOj">"
  50.  
  51. {
  52.  
  53. typeOj instOj;
  54.  
  55. public genClass(typeOj o)
  56.  
  57.  
  58. { instOj=o ; }
  59.  
  60.  
  61. public typeOj getType()
  62.  
  63. { return instOj; }
  64.  
  65.  
  66. interface IDBBase
  67. {
  68.  
  69. DataTable getDataTableSql(DataTable curTable,genClass<idcommand> cmd);
  70. ...
  71. }
  72.  
  73. class DBBase : IDBBase
  74. {
  75.  
  76. public DataTable getDataTableSql(DataTable curTable, genClass<SqlCommand> cmd)
  77. {
  78. ...
  79. }
  80.  
  81. }
Add Comment
Please, Sign In to add comment