Private Accessors in Visual Studio 2012

混江龙づ霸主 提交于 2019-12-05 07:46:09

Mark your members as "internal" and use the InternalsVisibleTo attribute. Simple to use and no type safety issues.

Maybe this posting Home-made Private Accessor for Visual Studio 2012+ will help you creating your own Private Accessor.

Regards,

Stefan

I started using the Dynamic Private Accessor feature that is part of the nuget package Chaining Assertion for MSTest and I am rather happy with it. One looses strong typing but at least the syntax is still readable. This works with the dynamic feature. There are also packages for other testing frameworks. Testing code looks like this:

var target = CreateMyObjectUnderTest();
dynamic dynamicTarget = target.AsDynamic();
Assert.AreEqual("abc", dynamicTarget.MyPrivateProperty);
Assert.AreEqual("xyz", dynamicTarget.PrivateMethod(123));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!