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

前端 未结 6 1372
春和景丽
春和景丽 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:14

    You could create a proxy, and send that proxy to your entity classes.

    class MyClass
    {
        public int MyProperty { get; set; }
    }
    
    class MyProxyClass
    {
        public MyProxyClass(MyClass myClass)
        {
            _myClass = myClass;
        }
    
        private MyClass _myClass;
    
        public int MyProperty
        {
            get { return _myClass.MyProperty; }
        }
    }
    

提交回复
热议问题