【发布时间】:2012-03-01 19:50:45
【问题描述】:
是否可以从 COM 公开的 .NET 程序集访问共享属性?
VBA
Dim appExcel As Object
Dim objAppSingleton As Object
Set objAppSingleton = CreateObject("Pitchbook.CommonUtils.Application.PitchbookAppSingleton")
appExcel = objAppSingleton.CurrentPitchbookExcelApp
VB.NET
<ProgId("Pitchbook.CommonUtils.Application.PitchbookAppSingleton")> _
Public Class PitchbookAppSingleton
Private Shared _currentPitchbookExcelApplication As PitchbookAppExcel
Private Shared _syncLockExcel As Object = New Object()
Public Shared ReadOnly Property CurrentPitchbookExcelApp As PitchbookAppExcel
Get
If _currentPitchbookExcelApplication Is Nothing Then
SyncLock [_syncLockExcel]
If _currentPitchbookExcelApplication Is Nothing Then
Dim currPitchbookExcelApplication As New PitchbookAppExcel()
_currentPitchbookExcelApplication = currPitchbookExcelApplication
End If
End SyncLock
End If
Return _currentPitchbookExcelApplication
End Get
End Property
End Class
Public Class PitchbookAppExcel
Inherits PitchbookApp
Protected Friend Sub New()
MyBase.New()
End Sub
End Class
appExcel = objAppSingleton.CurrentPitchbookExcelApp 行给出了错误: 运行时错误“438”: 对象不支持该属性或方法
【问题讨论】:
-
你不能从非共享属性声明中访问共享私有对象吗?