You can do this, as TGH suggested, with nested classes, except vice versa. Grid socket inside GridItem and make InformAddedToGrid private. Here I use a nested base class so that the public API remains the same. Note that none of your assembly can inherit from GridBase , because the constructor is internal.
public class GridItem { public class GridBase { internal GridBase() { } public void AddItem(GridItem item) { item.InformAddedToGrid(); } } private void InformAddedToGrid() { Debug.Log("I've been added to the grid"); } } public class Grid : GridItem.GridBase { }
Another option is to have GridItem explicitly implement the internal interface. Thus, none of your assembly can use the interface by name and therefore cannot call InformAddedToGrid .
public class Grid { public void AddItem(GridItem item) { ((IGridInformer)item).InformAddedToGrid(); } } public class GridItem : IGridInformer { void IGridInformer.InformAddedToGrid() { Debug.Log("I've been added to the grid"); } } internal interface IGridInformer { void InformAddedToGrid(); }
source share