code_junkie

Return Inherited Generics as Base Generic

Nov 13th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Public MustInherit Class BaseAbstractClass(Of T As WebControl)
  2. Inherits WebControl
  3.  
  4. Protected _item As T
  5.  
  6. Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
  7. _item.RenderControl(writer)
  8. End Sub
  9. End Class
  10.  
  11. Public Class ConcreteWrapper1
  12. Inherits BaseAbstractClass(Of CustomControlInheritedFromWebControl1)
  13.  
  14. Public Sub New(ByVal control As CustomControlInheritedFromWebControl1)
  15. MyBase._item = control
  16. End Sub
  17. End Class
  18.  
  19. Public Class CustomControlInheritedFromWebControl1
  20. Inherits WebControl
  21.  
  22. //not the correct comment markers but the coloring works better
  23. //do stuff here... Implm not important.
  24.  
  25. End Class
  26.  
  27. Public Class WebControlFactory
  28.  
  29. Public Shared Function GetWebControl() As BaseAbstractClass(Of WebControl)
  30.  
  31. Return New ConcreteWrapper1(New CustomControlInheritedFromWebControl1())
  32.  
  33. End Function
  34.  
  35. End Class
  36.  
  37. WebControl
  38. BAC inherits WebControl
  39. BAC(of T) inherits BAC
  40. Wrapper1 inherits BAC(of int)
  41. Wrapper2 inherits BAC(of string)
  42. Wrapper3 inherits BAC(of Foo)
  43. Wrapper4 inherits BAC(of Bar)
Add Comment
Please, Sign In to add comment