public static RecursiveObject <T> CreateOfDepth(int depth) { if (depth < 0) { throw new ArgumentOutOfRangeException("depth", "Must be non-negative"); } RecursiveObject <T> topMostParent = new RecursiveObject <T>(); RecursiveObject <T> currentParent = topMostParent; while (depth-- > 0) { currentParent.Inner = new RecursiveObject <T>(); currentParent = currentParent.Inner; } return(topMostParent); }
public void GetUsedProperties_TestComplexExpressionTargets() { RecursiveObject <int> recInt = RecursiveObject <int> .CreateOfDepth(1); RecursiveObject <string> recStr = RecursiveObject <string> .CreateOfDepth(2); RecursiveObject <string> deepestInnerStr = recStr.Inner.Inner; string suffix = "suffix"; recInt.Inner.FieldA = 3; recStr.PropertyB = "B"; deepestInnerStr.PropertyA = "A"; GetUsedPropertyTargets( () => deepestInnerStr.TrackFields().PropertyA. PadLeft(recInt.TrackFields().PropertyA * 2, ' ') + suffix ).Should().BeEquivalentTo(new object[] { recInt, deepestInnerStr }); }