English 中文(简体)
内部成员的精彩可见度
原标题:Fine-grained visibility for internal members

最近,我读到了分治法。 http://codebetter.com/blogs/patricksmacchia/archive/2008/12/08/advices-on-partition-code- through-net-assemblies.aspx”rel=“nofollow noreferer”>,:“将你/NET的集会数目减少到最低限度”。

我会同意更多! 我个人经常看到的原因之一是,人们只是想孤立一些法典,这样他们就能够把这些类型/方法内部化,并把它们单独纳入一个项目。

还有其他许多理由(无效或不)将守则分为几个议会,但 如果你想要孤立部分/单元,同时仍然将其设在一个图书馆,那么你如何做到这一点?

namespace MyAssembly.SomeApiInternals
{
     //Methods from this class should not 
     //be used outside MyAssembly.SomeApiInternals
     internal class Foo
     {              
          internal void Boo() { }
     }
}

namespace MyAssembly.AnotherPart
{
     public class Program
     {              
          public void Test() 
          {
               var foo = MyAssembly.SomeApiInternals.Foo();
               foo.Boo(); //Ok, not a compiler error but some red flag at least 
          }
     }
}             

如何限制某种类型/方法在same组装上其他类型/方法,但在这个名称空间之外?

(我只回答几个问题,看看人们如何投票)。)

感谢!

最佳回答

您可以把该守则放在不同的议会中,然后将集会与ILMerge 。 a. 安装后步骤......

问题回答

利用NDepend和CQL规则,这些规则体现了你想要的东西,并作为你建筑的一部分加以管理。 这些语言都对这种限制感兴趣。 (我一直注视着你的联系——你是really,试图在没有国民津贴的情况下这样做?) 您的回答应当排除或排除。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...