C # Properties Programming (2)

xiaoxiao2021-03-06  70

In fact, if you write your own properties, you can understand the realization mechanism of NUnit.

Assume Object OBJ

TYPE TYPE = Obj.gettype ()

Get the TYPE type of this object first

TestFixTureAttribute [] attributeArray = (TestFixTureAttribute []) TYPE.GETCUSTOMATTRIBUTES (TestFixTureAttribute), False;

The property definition for this object is obtained by reflection, such as [TestFixTure] attributes for the test class in NUnit

MethodInfo Minfo = Type.getMethod ("Method Name";

Get this object specifying method information TestAttribute [] attributeArray = (TestArRibute ", false; getting a property definition for this method, such as NUNIT test class [Test] The property NUnit is in operation, and it is definitely all method information through the Type.getMethods () method, then the properties of the analysis method are used to determine those methods need to test, such as when it encounters the Ignore property, it will skip the test this can guess Ignore attribute class defined substantially as follows: [AttributeUsage (AttributeTargets.Method)] public class IgnoreAttribute: attribute {private string describe; // description public IgnoreAttrebute (string info) {describe = info;} public string describe {Get {..}; set {..};}}

Set

AttributeTargets indicate that this property can only be used by the method. By a constructor, it is forced to enter some description information when using the Ignore property, such as [Ignore ("test pass")]

转载请注明原文地址:https://www.9cbs.com/read-87654.html

New Post(0)