vb.net – 实现属性必须具有匹配的’ReadOnly’或’WriteOnly’说明符

我有一个在idl文件中定义的接口,并尝试将vb6项目转换为vb.net.

转换从这个idl的tlb创建了interop,并且在vs2010中它抱怨该属性没有被实现(如下所示).有谁知道为什么?我甚至删除了实现并让vs2010重新生成存根,但仍然是错误.

idl中的示例界面..

[   uuid(...),
    version(2.0),
    dual,
    nonextensible,
    oleautomation
]
interface IExampleInterface : IDispatch
{
 ...
    [id(3), propget]
    HRESULT CloseDate ([out, retval] DATE* RetVal);
    [id(3), propput]
    HRESULT CloseDate ([in] DATE* InVal);
}

VB.Net类……

<System.Runtime.InteropServices.ProgId("Project1_NET.ClassExample")>
Public Class ClassExample
    Implements LibName.IExampleInterface

    Public Property CloseDate As Date Implements LibName.IExampleInterface.CloseDate
        Get
            Return mDate
        End Get
        Set(value As Date)
            mDate = value
        End Set
    End Property

最佳答案 DATE参数类型是问题.它不是DateTime或Date,它是Double.该声明在WTypes.h SDK头文件中给出,第725行为v7.1:

 typedef double DATE;

因此,通过将其声明为Double并根据需要来回转换来修复您的属性:

Public Property CloseDate As Double Implements LibName.IExampleInterface.CloseDate
    Get
        Return mDate.ToOADate
    End Get
    Set(value As Date)
        mDate = DateTime.FromOADate(value)
    End Set
End Property
点赞