public void ITypeDescriptorContextTest() { PropertyGrid pg = new PropertyGrid(); var rootObj = new NestedObj0(); rootObj.Property1 = new NestedObj1(); rootObj.Property1.Property2 = new NestedObj2(); rootObj.Property1.Property2.Property3 = new NestedObj3(); pg.SelectedObject = rootObj; GridItem gridItem_Property1 = pg.GetRootItem(); INestedObj ownerOf_Property1 = rootObj; CheckGridItem(ownerOf_Property1, "Property1", gridItem_Property1); GridItem gridItem_Property2 = gridItem_Property1.GridItems["Property2"]; INestedObj ownerOf_Property2 = rootObj.Property1; CheckGridItem(ownerOf_Property2, "Property2", gridItem_Property2); GridItem gridItem_Property3 = gridItem_Property2.GridItems["Property3"]; INestedObj ownerOf_Property3 = rootObj.Property1.Property2; CheckGridItem(ownerOf_Property3, "Property3", gridItem_Property3); }
public void CheckGridItem(INestedObj ownerObject, string propertyName, GridItem gridItem) { var context = gridItem as ITypeDescriptorContext; Assert.NotNull(gridItem, "gridItem is null (propertyName={0})", propertyName); Assert.NotNull(context, "gridItem is not ITypeDescriptorContext (propertyName={0})", propertyName); Assert.AreEqual(gridItem.Label, propertyName); Assert.AreSame(context.Instance, ownerObject); Assert.AreEqual(context.PropertyDescriptor.PropertyType, ownerObject.PropertyAsINestedObj.GetType()); Assert.AreEqual(context.PropertyDescriptor.Name, propertyName); }