protected void FriendAssert(IFriendKey key) { if (key == null || key.Id == null || key.Id.GetType() != typeof(TFriend)) { throw new Exception("No right to execute the called method."); } }
public void f(IFriendKey key) { FriendAssert(key); Console.WriteLine("ONLY class B can execute this method successfully, even though it is declared public."); }