重载分辨率失败,因为无法访问“新”对这些参数最具体: [英] Overload resolution failed because no accessible 'New' is most specific for these arguments:
问题描述
我现在的代码是:
导入System.ComponentModel
公共类UpdateList
继承System.Web.UI。 UserControl
私有m_dataSource As Object
< TypeConverter(System.Windows.Forms.Design.DataSourceConverter,System.Design)> _
< Category(Data)> _
< DefaultValue(Nothing)> _
公共属性DataSource()As Object
获取
返回Me.m_dataSource
结束Get
Set(value As Object)
如果Me.m_dataSource< ;>值然后
m_dataSource = value
tryDataBinding()
结束如果
结束集
结束属性
公共ReadOnly属性UpdateCount As Integer
获取
返回m_UpdateCount
结束获取
结束属性
受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)句柄Me.Load
End Sub
受保护的子tryDataBinding()
rep_Updates.DataSource = Me.m_dataSource
rep_Updates .DataBind()
End Sub
结束类
我在< DefaultValue(Nothing)>
中获得一个波浪线,并得到一个错误:
过载解析失败,因为无法访问新对于这些参数最为特殊:
'Public Sub New(value As Boolean)':not最具体的。
'Public Sub New(value As Byte)':不是最具体的。
'Public Sub New(value As Char)':不是最具体的。 >
这是什么意思?谢谢
更新
修复是将数据源的属性声明更改为...
私有m_dataSource As Object
公共属性DataSource()As Object
获取
返回Me.m_dataSource
结束Get
Set(value As Object)
m_dataSource = value
tryDataBinding()
结束集
结束属性
至少在WinForms DefaultValue属性ctor不能 Nothing
(对象浏览器中没有这样的定义)。 DefaultAttribute
不会定义初始值(尽管有名称),而是保留属性值的时间的比较值。在Webform和数据源的情况下,这似乎是可疑的,所以只需删除属性。
正如您注意到 TypeConverter
可能不合适。
I have a usercontrol with a repeater. Originally in page load I had code which grabbed data from the database and bound to the repeater. I now want to take this functionality outside of the usercontrol so that I can have more than one on the page and have them bind to different data.
My code now is:
Imports System.ComponentModel
Public Class UpdateList
Inherits System.Web.UI.UserControl
Private m_dataSource As Object
<TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")> _
<Category("Data")> _
<DefaultValue(Nothing)> _
Public Property DataSource() As Object
Get
Return Me.m_dataSource
End Get
Set(value As Object)
If Me.m_dataSource <> value Then
m_dataSource = value
tryDataBinding()
End If
End Set
End Property
Public ReadOnly Property UpdateCount As Integer
Get
Return m_UpdateCount
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub tryDataBinding()
rep_Updates.DataSource = Me.m_dataSource
rep_Updates.DataBind()
End Sub
End Class
I get a wavy line at <DefaultValue(Nothing)>
and get an error:
Overload resolution failed because no accessible 'New' is most specific for these arguments:
'Public Sub New(value As Boolean)': Not most specific.
'Public Sub New(value As Byte)': Not most specific.
'Public Sub New(value As Char)': Not most specific.
What does this mean? Thanks
UPDATE
The fix was to change the property declaration for datasource to...
Private m_dataSource As Object
Public Property DataSource() As Object
Get
Return Me.m_dataSource
End Get
Set(value As Object)
m_dataSource = value
tryDataBinding()
End Set
End Property
at least in WinForms the DefaultValue attribute ctor cant be Nothing
(there is no such definition in Object Browser). DefaultAttribute
doesnt define an initial starting value (in spite of the name), but the comparison value for when to persist a property value. This seems dubious anyway in the case of a webform and datasource, so just remove the attribute.
As you noted the TypeConverter
is probably out of place as well.
这篇关于重载分辨率失败,因为无法访问“新”对这些参数最具体:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!