Private Accessors in Visual Studio 2012

As far as I know, Visual Studio 2012 will not support private accessories. Can you tell me about possible alternatives? PrivateObject.Invoke () is not the best solution for me.

Thank you in advance!

+6
source share
3 answers

Mark your members as "internal" and use the InternalsVisibleTo attribute. Ease of use and lack of security issues.

+7
source

Perhaps this post by Home Private Accessor for Visual Studio 2012+ will help you create your own private accessory.

Hi,

Stephen

0
source

I started using the dynamic private access feature, which is part of the nuget Chain package for MSTest , and I am very pleased with it. One loses strong typing, but at least the syntax is still readable. This works with a dynamic function. There are also packages for other testing systems. The verification code is as follows:

var target = CreateMyObjectUnderTest(); dynamic dynamicTarget = target.AsDynamic(); Assert.AreEqual("abc", dynamicTarget.MyPrivateProperty); Assert.AreEqual("xyz", dynamicTarget.PrivateMethod(123)); 
0
source

Source: https://habr.com/ru/post/919845/


All Articles