添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. I'm trying to hide base methods in an inherited class, and I am using a method where a wrapper is used to return an interface of methods that are seen, like so:
vb.net Code:
  1. Public Class MyWrapper
  2.  
  3.     Private _MyStringList As MyStringList
  4.  
  5.     Public Sub New()
  6.         Me._MyStringList = New MyStringList
  7.     End Sub
  8.  
  9.     Private _List As IMyListFunctions
  10.     Public Property List() As IMyListFunctions
  11.         Get
  12.             Return _List
  13.         End Get
  14.         Set(ByVal value As IMyListFunctions)
  15.             _List = value
  16.         End Set
  17.     End Property
  18.  
  19.     Private Class MyStringList
  20.         Inherits List(Of String)
  21.         Implements IMyListFunctions
  22.  
  23.         Public Overloads Sub Add(ByVal item As String) Implements IMyListFunctions.Add
  24.             MyBase.Add(item)
  25.         End Sub
  26.  
  27.         Public Overloads Function Contains(ByVal item As String) As Boolean Implements IMyListFunctions.Contains
  28.             Return MyBase.Contains(item)
  29.         End Function
  30.  
  31.     End Class
  32.  
  33.     Public Interface IMyListFunctions
  34.         Sub Add(ByVal item As String) 'Allow Add
  35.         Function Contains(ByVal item As String) As Boolean 'Allow Contains
  36.     End Interface
  37.  
  38. End Class
And what I am basically wondering is if there is an easier way to do this. Is there some sort of Compile attribute I can apply instead?
EDIT: The best way to do this (Microsoft does this) is to use these Attributes:
vb.net Code:
  1. <System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)> _
  2. APropertyOrMethod
Overtop of a Method or Property, then if they are called throw NotSupportedExceptions. Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.