vb.net 类 ' 不能被索引,因为它没有默认属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24425975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:46:32  来源:igfitidea点击:

Class ' cannot be indexed because it has no default property

vb.net

提问by user3458266

I get the following error Class 'PropGenie_WebService.Branch' cannot be indexed because it has no default property.And I am not sure why. I have googled but don't get a proper explanation or fix. C# help welcome.

我收到以下错误Class 'PropGenie_WebService.Branch' cannot be indexed because it has no default property.我不知道为什么。我用谷歌搜索但没有得到正确的解释或修复。欢迎 C# 帮助。

My code in the branch.vb class:

我在 branch.vb 类中的代码:

Public Function Update() As Branch
    Return Update(Me, Path) 'error at update.
End Function

And in my Base class (Resources.vb) I have:

在我的基类(Resources.vb)中,我有:

Public Shared Function Update(Of T As {Resources, New})(resource As T, path As String) As T
        Dim request = CreateRequest(path & "/{id}", Method.PATCH)
        request.AddUrlSegment("id", resource.Id.ToString(CultureInfo.InvariantCulture))
        request.AddBody(resource)
        Dim Client = CreateClient()
        Dim responce = Client.Execute(Of T)(request)
        If responce.StatusCode <> HttpStatusCode.OK Then
            Throw New InvalidOperationException("Update Failed" & Convert.ToString(responce.StatusCode))
        End If
        Return responce.Data
    End Function

采纳答案by Magnus

You need to specify the class in which the shared function is also, or it will try to use the Updatefunction in the object you are in.

您还需要指定共享函数所在的类,否则它会尝试Update在您所在的对象中使用该函数。

Public Function Update() As Branch
    Return Resources.Update(Me, Path)
End Function