A、B、および C の 3 つの VB.net アセンブリを取り上げます。A は B を参照し、B は C を参照しますが、A は C を参照しません。次の 3 つのクラス (各アセンブリに 1 つ) があるとします。
アセンブリ A
Public Class View()
Public Property ViewModel as SomeViewModel
End Class
組立B
Public Class SomeViewModel()
'Compiler is ok with private variable _Model, doesn't complain.
Private _Model as SomeModel
Friend Sub New(Model as SomeModel)
Me._Model = Model
End Sub
'Compiler complains when Friend property is added, requiring A to directly
'reference C.
Friend ReadOnly Property UnderlyingModel as SomeModel
End Class
アセンブリ C
Public Class SomeModel()
Public Property ModelID as Integer
End Class
本質的に、アセンブリ C には、アセンブリ B の SomeViewModel によってラップされたモデル (SomeModel) が含まれています。 SomeViewModel は、"Friend" プロパティを介して AssemblyB の他のクラスにモデルを公開します。アセンブリ A のビューには SomeViewModel が含まれていますが、Friend 修飾子により、ビューから SomeViewModel.UnderlyingModel プロパティにアクセスできません。
この構成では、アセンブリ A のコンパイル時に VS 2010 で次のコンパイル エラーが発生します。
Error 3 Construct makes an indirect reference to project 'AssemblyC',
which contains 'AssemblyC.SomeModel'. Add a project reference to 'AssemblyC' to your
project.
アセンブリ A がアセンブリ C を参照することなく、Friend モディファイアを介して UnderlyingModel プロパティを公開する方法はありますか? アセンブリ A のビューはアセンブリ C のモデルを公開するプロパティにアクセスできないため、Friend モディファイアがこれを可能にしたと思いますか?