public void CreateIsVisibleMethod_ClassWithDynamicVisibleProperty_ReturnResultFromValidationMethod(bool isVisible) { // Setup var o = new ClassWithDynamicVisibleProperty(isVisible); // Call DynamicVisibleValidationMethodAttribute.IsPropertyVisible result = DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(o); // Assert Assert.AreEqual(isVisible, result("Property")); }
/// <summary> /// Determines whether the property is visible or not. /// </summary> /// <param name="value">The object.</param> /// <param name="propertyName">The name of the property of <paramref name="value"/>.</param> /// <returns><c>true</c> if the property is visible, <c>false</c> otherwise.</returns> /// <exception cref="MissingMemberException">Thrown when <paramref name="propertyName"/> /// does not correspond to a public property of <paramref name="value"/>.</exception> /// <exception cref="MissingMethodException">Thrown when there isn't a single method /// declared on <paramref name="value"/> marked with <see cref="DynamicVisibleValidationMethodAttribute"/> /// that is matching the signature defined by <see cref="DynamicVisibleValidationMethodAttribute.IsPropertyVisible"/>.</exception> public static bool IsVisible(object value, string propertyName) { if (string.IsNullOrEmpty(propertyName)) { return(BrowsableAttribute.Default.Browsable); } if (!IsPropertyDynamicallyVisible(value, propertyName)) { return(BrowsableAttribute.Default.Browsable); } DynamicVisibleValidationMethodAttribute.IsPropertyVisible isPropertyVisibleDelegate = DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(value); return(isPropertyVisibleDelegate(propertyName)); }