In C# 4.0, is there any way to make an otherwise private member of one class available only to a specific other class?

前端 未结 9 1987
旧时难觅i
旧时难觅i 2021-01-31 19:27

We\'re creating an object hierarchy where each item has a collection of other items, and each item also has a Parent property pointing to its parent item. Pretty st

9条回答
  •  我在风中等你
    2021-01-31 20:02

    One solution I've used to control visibility of class members is to define the class as partial, and then in a different namespace declare the class as partial, and define the special visibility members you want.

    This controls member visibility depending on the namespace chosen.

    The only thing you'll have to wrap your head around is referencing. It can get complex, but once you have it figured out, it works.

提交回复
热议问题