简体   繁体   English

如何在同一解决方案中从VB.NET项目访问C#内部属性?

[英]How to access a C# internal property from VB.NET project in same solution?

My Visual Studio 2008 solution contains both C# and VB.NET projects. 我的Visual Studio 2008解决方案包含C#和VB.NET项目。 From a VB.NET project, how can I access a C# property with its access modifier set to "internal"? 从VB.NET项目中,如何访问C#属性,并将其访问修饰符设置为“internal”?

You need to make the assembly's friends with the InternalsVisibleTo attribute. 您需要使用InternalsVisibleTo属性创建程序集的朋友。

Assuming that you don't sign your assemblies, it's as easy as adding an assembly level InternalsVisibleTo attribute to the C# project with the name of the VB.Net assembly. 假设您没有对程序集进行签名,就像使用VB.Net程序集的名称向C#项目添加程序集级别的InternalsVisibleTo属性一样简单。 Typically you do this in AssemblyInfo.cs (under the Properties folder) 通常,您在AssemblyInfo.cs中执行此操作(在“属性”文件夹下)

[assembly:InternalsVisibleTo("MyVbAssemblyName")]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM