Limiting access to a public setter to specific objects (C#)

前端 未结 6 1369
春和景丽
春和景丽 2021-01-16 09:48

I\'m trying to create a class (in C#) that serves as an environment for my application.

I\'m trying to make the class dynamic, and send it as a parameter to entities

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 10:04

    How about

    class Callee
    {
        public void SetX(TypeOfCaller caller, int value)
        {
        }
    }
    class TypeOfCaller
    {
        public void Do()
        {
            Callee instance;
            //..
            instance.SetX(this, 5);
        }
    }
    

    Doing so; you can also use Visual Studio' Find References feature! In case you want multiple types of caller; you can either opt for class hierarchy or can simply have required overloads

提交回复
热议问题