【问题标题】:Cannot refer to an instance member of a class不能引用类的实例成员
【发布时间】:2020-08-29 21:25:00
【问题描述】:

我想使用第二个属性 LogoWidth 来设置第一个属性的宽度,但我得到“无法从共享方法引用类的实例成员” 如果有人可以帮助我将不胜感激

<DetailViewLayoutAttribute(LayoutColumnPosition.Left, "Header Logo", LayoutGroupType.SimpleEditorsGroup, 1)>
<VisibleInListView(False), DevExpress.Xpo.DisplayName("Logo"), ImmediatePostData> '<RuleRequiredField("Logo", DefaultContexts.Save)>
<ImageEditor(ListViewImageEditorMode:=ImageEditorMode.PictureEdit,
DetailViewImageEditorMode:=ImageEditorMode.PictureEdit, ListViewImageEditorCustomHeight:=85, DetailViewImageEditorFixedHeight:=160, DetailViewImageEditorFixedWidth:=160)>
<Size(SizeAttribute.Unlimited)>
    Public Property Logo() As Byte()
        Get
            Return GetPropertyValue(Of Byte())("Logo")
        End Get
        Set
            '   If True Then
            SetPropertyValue(Of Byte())("Logo", Value)
            '  End If

        End Set
    End Property

    <DetailViewLayoutAttribute(LayoutColumnPosition.Right, "Header Logo", LayoutGroupType.SimpleEditorsGroup, 1)>
    <VisibleInListView(False), DevExpress.Xpo.DisplayName("Width"), ImmediatePostData> '<RuleRequiredField("LogoWidth", DefaultContexts.Save)>
    Public Property LogoWidth As Integer
        Get
            Return _LogoWidth
        End Get
        Set(ByVal Value As Integer)
            SetPropertyValue(NameOf(LogoWidth), _LogoWidth, Value)
        End Set
    End Property}

【问题讨论】:

    标签: vb.net xaf


    【解决方案1】:

    这是不可能的,因为实例成员只能被实例修改/调用/可见。下面的代码为您提供了一个小概念,但在这里您可以获得更多关于https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/modifiers/shared的信息

    Class ClassTest
    
        Public Property TestIsCalled As Integer
    
        Public Sub IncreaseTestByInstance()
            TestIsCalled += 1
        End Sub
    
        Shared Sub IncreaseTestByEveryWhereInNameSpace()
            ' Error
            ' Error - You MUST TO increase test by an instance method not by a shared method
            ' as TestIsCalled not exist when you call here as is an Instance Member not a Shared Member  
            TestIsCalled += 1
        End Sub
    
    End Class
    

    因此,根据您的代码,解决方案有两种:

    1. 在 例如SubFunction(它是什么)
    2. 或更改Shared Property 中的这两个属性。

    一切都取决于您的应用场景。

    【讨论】:

    • 感谢属性DetailViewImageEditorFixedWidth:=160上设置宽度
    • 你的代码不清楚。有两个属性,仍然是个谜。但是,请参阅您发布的消息“无法从共享方法中引用类的实例成员”,问题是上面的答案解释了。某处(在您的代码中,我们看不到它的限制)是一个称为实例成员的共享方法。你应该在哪里找到。
    • 另外你必须知道属性是类并且有属性、方法等,这些也可能是共享或实例成员。
    猜你喜欢
    • 2015-11-27
    • 2020-04-07
    • 1970-01-01
    • 2016-05-23
    • 2016-01-01
    • 2016-09-09
    • 2017-06-06
    相关资源
    最近更新 更多