C# - RectangleF will not Offset when used as Property

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MSwaffer
    New Member
    • Aug 2008
    • 2

    C# - RectangleF will not Offset when used as Property

    When I run the following tests (In NUnit):

    Code:
        [Test]
        public void ShouldOffsetRectangle() {
          RectangleF standAloneRect = new RectangleF(0, 0, 10, 10);
          standAloneRect.Offset(1, 1);
          Assert.AreEqual(1, standAloneRect.X, "standAlone failed");
        }
    
        [Test]
        public void ShouldOffsetRectangleAsProperty() {
          TestRect propertyRect = new TestRect();
          propertyRect.Rectangle = new RectangleF(0, 0, 10, 10);
          propertyRect.Rectangle.Offset(1, 1);
          Assert.AreEqual(1, propertyRect.Rectangle.X, "propertyRect failed");
        }
    
        private class TestRect {
          public RectangleF Rectangle { get; set; }
        }
    The second test fails... it says that the propertyRect.Re ctangle.X is still 0.

    Any ideas why this behavior might be? I am stumped at this point.

    Obviously I can get around it by offsetting the Rectangle before assigning it, I am just trying to figure out why I am seeing this behavior.

    Thanks,

    Matt
Working...