使内部类对其他程序集可见

时间:2013-01-16 08:36:07

标签: c# linqpad internals

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

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

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

2 个答案:

答案 0 :(得分:60)

我刚刚上传了a new beta,可以让它发挥作用。

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

[assembly: InternalsVisibleTo("LINQPadQuery")]

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

让我知道你是如何相处的。

答案 1 :(得分:1)

您还可以将项目属性转到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")]