45

是否可以使我的程序集中的内部类对其他程序集可见?

我知道 AssemblyInfo 文件和[assembly: InternalsVisibleTo()]属性,但在我的情况下它不起作用。

主要目的是让从 LINQPAD 调用方法成为可能,所以这[assembly: InternalsVisibleTo("LINQPad")]行不通。我不知道为什么。在我的项目中,我使用了依赖解析器,在 LINQPAD 中很难做到这一点。有什么建议么?

4

2 回答 2

72

我刚刚上传了一个新的测试版,它允许这个工作。

将以下属性添加到您希望 LINQPad 访问其内部的库:

[assembly: InternalsVisibleTo("LINQPadQuery")]

您还需要在 LINQPad 的首选项(编辑 | 首选项 | 高级)中启用此功能。

让我知道你们相处得如何。

于 2013-01-17T08:03:36.840 回答
3

您还可以将项目属性转到 AssemblyInfo.cs 文件并在那里进行设置。

例如:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("*****)]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("*****")]
[assembly: AssemblyProduct("*****")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("[HERE IS YOUR ASSEMBLY WHERE YOU WANT TO SEE INTERNALS OF CURRENT ASSEMBLY")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6fbd2c14-031d-48cc-9cc6-f1b85d701e89")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
于 2020-07-23T14:40:20.337 回答