Index: Core/Common/src/Core.Common.Utils/Attributes/DynamicReadOnlyAttribute.cs
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/src/Core.Common.Utils/Attributes/DynamicReadOnlyAttribute.cs (.../DynamicReadOnlyAttribute.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Common/src/Core.Common.Utils/Attributes/DynamicReadOnlyAttribute.cs (.../DynamicReadOnlyAttribute.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -28,32 +28,24 @@
/// When there isn't a single method
/// declared on marked with
/// and/or isn't matching the signature defined by .
- public static bool IsDynamicReadOnly(object obj, string propertyName)
+ public static bool IsReadOnly(object obj, string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
{
- return false;
+ return ReadOnlyAttribute.Default.IsReadOnly;
}
var isDynamicReadOnlyProperty = PropertyIsDynamicallyReadOnly(obj, propertyName);
if (!isDynamicReadOnlyProperty)
{
- return false;
+ return ReadOnlyAttribute.Default.IsReadOnly;
}
var isPropertyReadOnlyDelegate = DynamicReadOnlyValidationMethodAttribute.CreateIsReadOnlyMethod(obj);
return isPropertyReadOnlyDelegate(propertyName);
}
- ///
- /// Determines if an object's property is marked with .
- ///
- /// The object.
- /// Name of the property.
- /// True if the attribute is defined, false otherwise.
- ///
- /// does not correspond to a public property of .
private static bool PropertyIsDynamicallyReadOnly(object obj, string propertyName)
{
var propertyInfo = obj.GetType().GetProperty(propertyName);
Index: Core/Common/src/Core.Common.Utils/Attributes/DynamicReadOnlyValidationMethodAttribute.cs
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/src/Core.Common.Utils/Attributes/DynamicReadOnlyValidationMethodAttribute.cs (.../DynamicReadOnlyValidationMethodAttribute.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Common/src/Core.Common.Utils/Attributes/DynamicReadOnlyValidationMethodAttribute.cs (.../DynamicReadOnlyValidationMethodAttribute.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -11,6 +11,7 @@
/// method should be public and have the signature of .
///
///
+ [AttributeUsage(AttributeTargets.Method)]
public class DynamicReadOnlyValidationMethodAttribute : Attribute
{
///
Index: Core/Common/src/Core.Common.Utils/Attributes/DynamicVisibleAttribute.cs
===================================================================
diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/src/Core.Common.Utils/Attributes/DynamicVisibleAttribute.cs (.../DynamicVisibleAttribute.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944)
+++ Core/Common/src/Core.Common.Utils/Attributes/DynamicVisibleAttribute.cs (.../DynamicVisibleAttribute.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -1,93 +1,61 @@
using System;
-using System.Linq;
-using System.Reflection;
+using System.ComponentModel;
-using Core.Common.Utils.Properties;
+using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resource;
namespace Core.Common.Utils.Attributes
{
///
- /// Hides or shows a property. When this attribute is used on a property -
- /// a class containing that property must contain a single validation method
- /// (argument propertyName as string, return bool) marked using
- /// attribute.
+ /// Marks property as a conditional visible property. When this attribute is declared
+ /// on a property, the declaring a class should have a public method marked with
+ /// to be used to evaluate if
+ /// that property should be visible or not.
///
+ ///
+ ///
+ /// This attribute provides a run-time alternative to .
+ [AttributeUsage(AttributeTargets.Property)]
public class DynamicVisibleAttribute : Attribute
{
- public static bool IsDynamicVisible(object obj, string propertyName)
+ ///
+ /// Determines whether the property is visible or not.
+ ///
+ /// The object.
+ /// Name of the property of .
+ /// True if the property is visible, false otherwise.
+ ///
+ /// does not correspond to a public property of .
+ /// When there isn't a single method
+ /// declared on marked with
+ /// and/or isn't matching the signature defined by .
+ public static bool IsVisible(object obj, string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
{
- return false;
+ return BrowsableAttribute.Default.Browsable;
}
- // todo: caching!!!!
- var propertyInfo = obj.GetType().GetProperty(propertyName);
- if (propertyInfo == null)
+ var isPropertyWithDynamicVisibility = PropertyIsDynamicallyVisible(obj, propertyName);
+ if (!isPropertyWithDynamicVisibility)
{
- throw new MissingMemberException(string.Format(Resource.Could_not_find_property_0_on_type_1_, propertyName,
- obj.GetType()));
+ return BrowsableAttribute.Default.Browsable;
}
- if (!propertyInfo.GetCustomAttributes(typeof(DynamicVisibleAttribute), false).Any())
- {
- return false;
- }
+ var isPropertyVisibleDelegate = DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(obj);
- var validationMethod = GetDynamicVisibleValidationMethod(obj);
-
- // check if property should be read-only
- if (validationMethod == null)
- {
- throw new MissingMethodException(
- String.Format(Resource.DynamicVisibleAttribute_IsDynamicVisible_0_uses_DynamicVisibleAttribute_but_does_not_have_method_marked_using_DynamicVisibleValidationMethodAttribute, obj));
- }
-
- return (bool) validationMethod.Invoke(obj, new[]
- {
- propertyName
- });
+ return isPropertyVisibleDelegate(propertyName);
}
- private static MethodInfo GetDynamicVisibleValidationMethod(object o)
+ private static bool PropertyIsDynamicallyVisible(object obj, string propertyName)
{
- var type = o.GetType();
-
- var validationMethods =
- type.GetMethods().Where(
- methodInfo =>
- methodInfo.GetCustomAttributes(false).Any(a => a is DynamicVisibleValidationMethodAttribute)).
- ToList();
-
- if (!validationMethods.Any())
+ var propertyInfo = obj.GetType().GetProperty(propertyName);
+ if (propertyInfo == null)
{
- throw new MissingMethodException("DynamicVisibleValidationMethodAttribute not found (or not public), class: " + type);
+ throw new MissingMemberException(string.Format(CoreCommonUtilsResources.Could_not_find_property_0_on_type_1_, propertyName,
+ obj.GetType()));
}
- if (validationMethods.Count() > 1)
- {
- throw new MissingMethodException("Only one DynamicVisibleValidationMethodAttribute is allowed per class: " + type);
- }
-
- var validationMethod = validationMethods.First();
-
- // check return type and arguments
- if (validationMethod.ReturnType != typeof(bool))
- {
- throw new MissingMethodException("DynamicVisibleValidationMethodAttribute must use bool as a return type, class: " + type);
- }
-
- if (validationMethod.GetParameters().Length != 1)
- {
- throw new MissingMethodException("DynamicVisibleValidationMethodAttribute has incorrect number of arguments, should be 1 of type string, class: " + type);
- }
-
- if (validationMethod.GetParameters()[0].ParameterType != typeof(string))
- {
- throw new MissingMethodException("DynamicVisibleValidationMethodAttribute has incorrect argument type, should be of type string, class: " + type);
- }
-
- return validationMethod;
+ return IsDefined(propertyInfo, typeof(DynamicVisibleAttribute));
}
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Utils/Attributes/DynamicVisibleValidationMethodAttribute.cs
===================================================================
diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/src/Core.Common.Utils/Attributes/DynamicVisibleValidationMethodAttribute.cs (.../DynamicVisibleValidationMethodAttribute.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944)
+++ Core/Common/src/Core.Common.Utils/Attributes/DynamicVisibleValidationMethodAttribute.cs (.../DynamicVisibleValidationMethodAttribute.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -1,12 +1,92 @@
using System;
+using System.Linq;
+using System.Reflection;
+using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resource;
+
namespace Core.Common.Utils.Attributes
{
///
- /// Used to mark method as a validation method used to check if property
- /// should be used or not. The method should be in the format:
- /// bool IsVisible(string propertyName)
+ /// Marks a method to be used to determine if a property should be shown or not. The
+ /// method should be public and have the signature of .
///
///
- public class DynamicVisibleValidationMethodAttribute : Attribute {}
+ [AttributeUsage(AttributeTargets.Method)]
+ public class DynamicVisibleValidationMethodAttribute : Attribute
+ {
+ ///
+ /// Required method signature when marking a method with .
+ ///
+ /// Name of the property to be checked.
+ /// True if the referred property should be visible, false if it should be hidden.
+ public delegate bool IsPropertyVisible(string propertyName);
+
+ ///
+ /// Creates a delegate that can be used to determine if a property should be visible.
+ ///
+ /// The object instance declaring the validation method.
+ /// The delegate.
+ /// When there isn't a single method
+ /// declared on marked with
+ /// and/or isn't matching the signature defined by .
+ public static IsPropertyVisible CreateIsVisibleMethod(object target)
+ {
+ var methodInfo = GetIsVisibleMethod(target);
+ ValidateMethodInfo(methodInfo);
+ return CreateIsPropertyVisibleDelegate(target, methodInfo);
+ }
+
+ private static IsPropertyVisible CreateIsPropertyVisibleDelegate(object target, MethodInfo methodInfo)
+ {
+ return (IsPropertyVisible)Delegate.CreateDelegate(typeof(IsPropertyVisible), target, methodInfo);
+ }
+
+ private static void ValidateMethodInfo(MethodInfo methodInfo)
+ {
+ if (methodInfo.ReturnType != typeof(bool))
+ {
+ var message = String.Format(CoreCommonUtilsResources.DynamicVisibleValidationMethod_must_return_bool_on_Class_0_,
+ methodInfo.DeclaringType);
+ throw new MissingMethodException(message);
+ }
+
+ ParameterInfo[] parameterInfos = methodInfo.GetParameters();
+ if (parameterInfos.Length != 1)
+ {
+ var message = String.Format(CoreCommonUtilsResources.DynamicVisibleValidationMethod_incorrect_argument_count_must_be_one_string_argument_on_Class_0_,
+ methodInfo.DeclaringType);
+ throw new MissingMethodException(message);
+ }
+
+ if (parameterInfos[0].ParameterType != typeof(string))
+ {
+ var message = String.Format(CoreCommonUtilsResources.DynamicVisibleValidationMethod_must_have_string_argument_on_Class_0_,
+ methodInfo.DeclaringType);
+ throw new MissingMethodException(message);
+ }
+ }
+
+ private static MethodInfo GetIsVisibleMethod(object obj)
+ {
+ var validationMethods = obj.GetType().GetMethods()
+ .Where(methodInfo => IsDefined(methodInfo, typeof(DynamicVisibleValidationMethodAttribute)))
+ .ToArray();
+
+ if (validationMethods.Length == 0)
+ {
+ var message = String.Format(CoreCommonUtilsResources.DynamicVisibleValidationMethod_not_found_or_not_public_on_Class_0_,
+ obj.GetType());
+ throw new MissingMethodException(message);
+ }
+
+ if (validationMethods.Length > 1)
+ {
+ var message = String.Format(CoreCommonUtilsResources.DynamicVisibleValidationMethod_only_one_allowed_per_Class_0_,
+ obj.GetType());
+ throw new MissingMethodException(message);
+ }
+
+ return validationMethods[0];
+ }
+ }
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Utils/Properties/Resource.Designer.cs
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/src/Core.Common.Utils/Properties/Resource.Designer.cs (.../Resource.Designer.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Common/src/Core.Common.Utils/Properties/Resource.Designer.cs (.../Resource.Designer.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -126,16 +126,52 @@
}
///
- /// Looks up a localized string similar to {0} gebruikt DynamicVisibleAttribute, maar heeft geen methode gemarkeerd met DynamicVisibleValidationMethodAttribute..
+ /// Looks up a localized string similar to DynamicVisibleValidationMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}..
///
- internal static string DynamicVisibleAttribute_IsDynamicVisible_0_uses_DynamicVisibleAttribute_but_does_not_have_method_marked_using_DynamicVisibleValidationMethodAttribute {
+ internal static string DynamicVisibleValidationMethod_incorrect_argument_count_must_be_one_string_argument_on_Class_0_ {
get {
- return ResourceManager.GetString("DynamicVisibleAttribute_IsDynamicVisible_0_uses_DynamicVisibleAttribute_but_does_" +
- "not_have_method_marked_using_DynamicVisibleValidationMethodAttribute", resourceCulture);
+ return ResourceManager.GetString("DynamicVisibleValidationMethod_incorrect_argument_count_must_be_one_string_argume" +
+ "nt_on_Class_0_", resourceCulture);
}
}
///
+ /// Looks up a localized string similar to Argument van DynamicVisibleValidationMethod moet van het type 'string' zijn. Klasse: {0}..
+ ///
+ internal static string DynamicVisibleValidationMethod_must_have_string_argument_on_Class_0_ {
+ get {
+ return ResourceManager.GetString("DynamicVisibleValidationMethod_must_have_string_argument_on_Class_0_", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to DynamicVisibleValidationMethod moet 'bool' als 'return type' hebben. Klasse: {0}..
+ ///
+ internal static string DynamicVisibleValidationMethod_must_return_bool_on_Class_0_ {
+ get {
+ return ResourceManager.GetString("DynamicVisibleValidationMethod_must_return_bool_on_Class_0_", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to DynamicVisibleValidationMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}..
+ ///
+ internal static string DynamicVisibleValidationMethod_not_found_or_not_public_on_Class_0_ {
+ get {
+ return ResourceManager.GetString("DynamicVisibleValidationMethod_not_found_or_not_public_on_Class_0_", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Slechts één DynamicVisibleValidationMethod toegestaan per klasse: {0}..
+ ///
+ internal static string DynamicVisibleValidationMethod_only_one_allowed_per_Class_0_ {
+ get {
+ return ResourceManager.GetString("DynamicVisibleValidationMethod_only_one_allowed_per_Class_0_", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Parameter 'GroupSize' moet groter zijn dan 0..
///
internal static string EnumerableExtensions_SplitInGroups_GroupSize_must_be_greater_than_0 {
Index: Core/Common/src/Core.Common.Utils/Properties/Resource.resx
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/src/Core.Common.Utils/Properties/Resource.resx (.../Resource.resx) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Common/src/Core.Common.Utils/Properties/Resource.resx (.../Resource.resx) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -144,9 +144,6 @@
Kon eigenschap {0} van type {1} niet vinden.
-
- {0} gebruikt DynamicVisibleAttribute, maar heeft geen methode gemarkeerd met DynamicVisibleValidationMethodAttribute.
-
Geen 'default constructor' gevonden voor type {0}.
@@ -177,4 +174,19 @@
'{0}' is geen geldige expressie voor deze methode.
+
+ DynamicVisibleValidationMethod moet 'bool' als 'return type' hebben. Klasse: {0}.
+
+
+ DynamicVisibleValidationMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}.
+
+
+ Argument van DynamicVisibleValidationMethod moet van het type 'string' zijn. Klasse: {0}.
+
+
+ DynamicVisibleValidationMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}.
+
+
+ Slechts één DynamicVisibleValidationMethod toegestaan per klasse: {0}.
+
\ No newline at end of file
Index: Core/Common/src/Core.Common.Utils/PropertyBag/DynamicPropertyBag.cs
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/src/Core.Common.Utils/PropertyBag/DynamicPropertyBag.cs (.../DynamicPropertyBag.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Common/src/Core.Common.Utils/PropertyBag/DynamicPropertyBag.cs (.../DynamicPropertyBag.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -56,7 +56,7 @@
{
attributeList.RemoveAll(x => x is ReadOnlyAttribute);
- if (DynamicReadOnlyAttribute.IsDynamicReadOnly(WrappedObject, propertySpec.Name))
+ if (DynamicReadOnlyAttribute.IsReadOnly(WrappedObject, propertySpec.Name))
{
//condition is true: the dynamic attribute should be applied (as static attribute)
attributeList.Add(new ReadOnlyAttribute(true)); //add static read only attribute
@@ -67,7 +67,7 @@
{
attributeList.RemoveAll(x => x is BrowsableAttribute);
- if (!DynamicVisibleAttribute.IsDynamicVisible(WrappedObject, propertySpec.Name))
+ if (!DynamicVisibleAttribute.IsVisible(WrappedObject, propertySpec.Name))
{
attributeList.Add(new BrowsableAttribute(false));
}
Index: Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicReadOnlyAttributeTest.cs
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicReadOnlyAttributeTest.cs (.../DynamicReadOnlyAttributeTest.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicReadOnlyAttributeTest.cs (.../DynamicReadOnlyAttributeTest.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -23,50 +23,50 @@
[Test]
[TestCase("")]
[TestCase(null)]
- public void IsDynamicReadOnly_NoPropertyName_ReturnFalse(string propertyName)
+ public void IsReadOnly_NoPropertyName_ReturnFalse(string propertyName)
{
// Call
- var isReadOnly = DynamicReadOnlyAttribute.IsDynamicReadOnly(new object(), propertyName);
+ var isReadOnly = DynamicReadOnlyAttribute.IsReadOnly(new object(), propertyName);
// Assert
Assert.IsFalse(isReadOnly);
}
[Test]
- public void IsDynamicReadOnly_GivenPropertyNameDoesNotExistOnObject_ThrowMissingMemberException()
+ public void IsReadOnly_GivenPropertyNameDoesNotExistOnObject_ThrowMissingMemberException()
{
// Setup
var o = new object();
// Call
- TestDelegate call = () => DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "NotExistingProperty");
+ TestDelegate call = () => DynamicReadOnlyAttribute.IsReadOnly(o, "NotExistingProperty");
// Assert
var exceptionMessage = Assert.Throws(call).Message;
Assert.AreEqual(string.Format("Kon eigenschap NotExistingProperty van type {0} niet vinden.", o.GetType()), exceptionMessage);
}
[Test]
- public void IsDynamicReadOnly_GivenPropertyDoesNotHaveDynamicReadOnlyAttribute_ReturnFalse()
+ public void IsReadOnly_GivenPropertyDoesNotHaveDynamicReadOnlyAttribute_ReturnFalse()
{
// Setup
var o = new ClassWithPropertyWithoutDynamicReadOnlyAttribute();
// Call
- var isReadOnly = DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "Property");
+ var isReadOnly = DynamicReadOnlyAttribute.IsReadOnly(o, "Property");
// Assert
Assert.IsFalse(isReadOnly);
}
[Test]
- public void IsDynamicReadOnly_ClassLacksDynamicReadOnlyValidationMethod_ThrowsMissingMethodException()
+ public void IsReadOnly_ClassLacksDynamicReadOnlyValidationMethod_ThrowsMissingMethodException()
{
// Setup
var o = new InvalidClassWithDynamicReadOnlyPropertyButNoValidationMethod();
// Call
- TestDelegate call = () => DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "Property");
+ TestDelegate call = () => DynamicReadOnlyAttribute.IsReadOnly(o, "Property");
// Assert
var exceptionMessage = Assert.Throws(call).Message;
@@ -76,13 +76,13 @@
}
[Test]
- public void IsDynamicReadOnly_ClassHasMultipleDynamicReadOnlyValidationMethods_ThrowsMissingMethodException()
+ public void IsReadOnly_ClassHasMultipleDynamicReadOnlyValidationMethods_ThrowsMissingMethodException()
{
// Setup
var o = new InvalidClassWithDynamicReadOnlyPropertyAndMultipleValidationMethod();
// Call
- TestDelegate call = () => DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "Property");
+ TestDelegate call = () => DynamicReadOnlyAttribute.IsReadOnly(o, "Property");
// Assert
var exceptionMessage = Assert.Throws(call).Message;
@@ -92,13 +92,13 @@
}
[Test]
- public void IsDynamicReadOnly_ClassHasDynamicReadOnlyValidationMethodWithNonBoolReturnType_ThrowsMissingMethodException()
+ public void IsReadOnly_ClassHasDynamicReadOnlyValidationMethodWithNonBoolReturnType_ThrowsMissingMethodException()
{
// Setup
var o = new InvalidClassWithDynamicReadOnlyPropertyButValidationMethodReturnsIncorrectValueType();
// Call
- TestDelegate call = () => DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "Property");
+ TestDelegate call = () => DynamicReadOnlyAttribute.IsReadOnly(o, "Property");
// Assert
var exceptionMessage = Assert.Throws(call).Message;
@@ -108,13 +108,13 @@
}
[Test]
- public void IsDynamicReadOnly_ClassHasDynamicReadOnlyValidationMethodWithIncorrectArgumentCount_ThrowsMissingMethodException()
+ public void IsReadOnly_ClassHasDynamicReadOnlyValidationMethodWithIncorrectArgumentCount_ThrowsMissingMethodException()
{
// Setup
var o = new InvalidClassWithDynamicReadOnlyPropertyButValidationMethodNotOneArgument();
// Call
- TestDelegate call = () => DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "Property");
+ TestDelegate call = () => DynamicReadOnlyAttribute.IsReadOnly(o, "Property");
// Assert
var exceptionMessage = Assert.Throws(call).Message;
@@ -124,13 +124,13 @@
}
[Test]
- public void IsDynamicReadOnly_ClassHasDynamicReadOnlyValidationMethodWithIncorrectArgumentType_ThrowsMissingMethodException()
+ public void IsReadOnly_ClassHasDynamicReadOnlyValidationMethodWithIncorrectArgumentType_ThrowsMissingMethodException()
{
// Setup
var o = new InvalidClassWithDynamicReadOnlyPropertyButValidationMethodArgumentNotString();
// Call
- TestDelegate call = () => DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "Property");
+ TestDelegate call = () => DynamicReadOnlyAttribute.IsReadOnly(o, "Property");
// Assert
var exceptionMessage = Assert.Throws(call).Message;
@@ -142,13 +142,13 @@
[Test]
[TestCase(false)]
[TestCase(true)]
- public void IsDynamicReadOnly_ClassWithDynamicReadOnlyProperty_ReturnResultFromValidationMethod(bool isReadOnly)
+ public void IsReadOnly_ClassWithDynamicReadOnlyProperty_ReturnResultFromValidationMethod(bool isReadOnly)
{
// Setup
var o = new ClassWithDynamicReadOnlyProperty(isReadOnly);
// Call
- var result = DynamicReadOnlyAttribute.IsDynamicReadOnly(o, "Property");
+ var result = DynamicReadOnlyAttribute.IsReadOnly(o, "Property");
// Assert
Assert.AreEqual(isReadOnly, result);
Index: Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicVisibleAttributeTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicVisibleAttributeTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicVisibleAttributeTest.cs (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -0,0 +1,157 @@
+using System;
+
+using Core.Common.Utils.Attributes;
+using Core.Common.Utils.Test.Attributes.TestCaseClasses;
+
+using NUnit.Framework;
+
+namespace Core.Common.Utils.Test.Attributes
+{
+ [TestFixture]
+ public class DynamicVisibleAttributeTest
+ {
+ [Test]
+ public void DefaultConstructor_ExpectedValues()
+ {
+ // Call
+ var attribute = new DynamicVisibleAttribute();
+
+ // Assert
+ Assert.IsInstanceOf(attribute);
+ }
+
+ [Test]
+ [TestCase("")]
+ [TestCase(null)]
+ public void IsVisible_NoPropertyName_ReturnTrue(string propertyName)
+ {
+ // Call
+ var isReadOnly = DynamicVisibleAttribute.IsVisible(new object(), propertyName);
+
+ // Assert
+ Assert.IsTrue(isReadOnly);
+ }
+
+ [Test]
+ public void IsVisible_GivenPropertyNameDoesNotExistOnObject_ThrowMissingMemberException()
+ {
+ // Setup
+ var o = new object();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleAttribute.IsVisible(o, "NotExistingProperty");
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ Assert.AreEqual(string.Format("Kon eigenschap NotExistingProperty van type {0} niet vinden.", o.GetType()), exceptionMessage);
+ }
+
+ [Test]
+ public void IsVisible_GivenPropertyDoesNotHaveDynamicVisibleAttribute_ReturnTrue()
+ {
+ // Setup
+ var o = new ClassWithPropertyWithoutDynamicVisibleAttribute();
+
+ // Call
+ var isReadOnly = DynamicVisibleAttribute.IsVisible(o, "Property");
+
+ // Assert
+ Assert.IsTrue(isReadOnly);
+ }
+
+ [Test]
+ public void IsVisible_ClassLacksDynamicVisibleValidationMethod_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButNoValidationMethod();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleAttribute.IsVisible(o, "Property");
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("DynamicVisibleValidationMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void IsVisible_ClassHasMultipleDynamicVisibleValidationMethods_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyAndMultipleValidationMethod();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleAttribute.IsVisible(o, "Property");
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("Slechts één DynamicVisibleValidationMethod toegestaan per klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void IsVisible_ClassHasDynamicVisibleValidationMethodWithNonBoolReturnType_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButValidationMethodReturnsIncorrectValueType();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleAttribute.IsVisible(o, "Property");
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("DynamicVisibleValidationMethod moet 'bool' als 'return type' hebben. Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void IsVisible_ClassHasDynamicVisibleValidationMethodWithIncorrectArgumentCount_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButValidationMethodNotOneArgument();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleAttribute.IsVisible(o, "Property");
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("DynamicVisibleValidationMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void IsVisible_ClassHasDynamicVisibleValidationMethodWithIncorrectArgumentType_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButValidationMethodArgumentNotString();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleAttribute.IsVisible(o, "Property");
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("Argument van DynamicVisibleValidationMethod moet van het type 'string' zijn. Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ [TestCase(false)]
+ [TestCase(true)]
+ public void IsVisible_ClassWithDynamicVisibleProperty_ReturnResultFromValidationMethod(bool isReadOnly)
+ {
+ // Setup
+ var o = new ClassWithDynamicVisibleProperty(isReadOnly);
+
+ // Call
+ var result = DynamicVisibleAttribute.IsVisible(o, "Property");
+
+ // Assert
+ Assert.AreEqual(isReadOnly, result);
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicVisibleValidationMethodAttributeTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicVisibleValidationMethodAttributeTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Utils.Test/Attributes/DynamicVisibleValidationMethodAttributeTest.cs (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -0,0 +1,108 @@
+using System;
+
+using Core.Common.Utils.Attributes;
+using Core.Common.Utils.Test.Attributes.TestCaseClasses;
+
+using NUnit.Framework;
+
+namespace Core.Common.Utils.Test.Attributes
+{
+ [TestFixture]
+ public class DynamicVisibleValidationMethodAttributeTest
+ {
+ [Test]
+ public void CreateIsVisibleMethod_ClassLacksDynamicVisibleValidationMethod_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButNoValidationMethod();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(o);
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("DynamicVisibleValidationMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void CreateIsVisibleMethod_ClassHasMultipleDynamicVisibleValidationMethods_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyAndMultipleValidationMethod();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(o);
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("Slechts één DynamicVisibleValidationMethod toegestaan per klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void CreateIsVisibleMethod_ClassHasDynamicVisibleValidationMethodWithNonBoolReturnType_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButValidationMethodReturnsIncorrectValueType();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(o);
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("DynamicVisibleValidationMethod moet 'bool' als 'return type' hebben. Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void CreateIsVisibleMethod_ClassHasDynamicVisibleValidationMethodWithIncorrectArgumentCount_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButValidationMethodNotOneArgument();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(o);
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("DynamicVisibleValidationMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ public void CreateIsVisibleMethod_ClassHasDynamicVisibleValidationMethodWithIncorrectArgumentType_ThrowsMissingMethodException()
+ {
+ // Setup
+ var o = new InvalidClassWithDynamicVisiblePropertyButValidationMethodArgumentNotString();
+
+ // Call
+ TestDelegate call = () => DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(o);
+
+ // Assert
+ var exceptionMessage = Assert.Throws(call).Message;
+ var expectedMessage = string.Format("Argument van DynamicVisibleValidationMethod moet van het type 'string' zijn. Klasse: {0}.",
+ o.GetType());
+ Assert.AreEqual(expectedMessage, exceptionMessage);
+ }
+
+ [Test]
+ [TestCase(false)]
+ [TestCase(true)]
+ public void CreateIsVisibleMethod_ClassWithDynamicVisibleProperty_ReturnResultFromValidationMethod(bool isReadOnly)
+ {
+ // Setup
+ var o = new ClassWithDynamicVisibleProperty(isReadOnly);
+
+ // Call
+ var result = DynamicVisibleValidationMethodAttribute.CreateIsVisibleMethod(o);
+
+ // Assert
+ Assert.AreEqual(isReadOnly, result("Property"));
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Utils.Test/Attributes/TestCaseClasses/DynamicVisibilityTestCases.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Utils.Test/Attributes/TestCaseClasses/DynamicVisibilityTestCases.cs (revision 0)
+++ Core/Common/test/Core.Common.Utils.Test/Attributes/TestCaseClasses/DynamicVisibilityTestCases.cs (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -0,0 +1,88 @@
+using Core.Common.Utils.Attributes;
+
+namespace Core.Common.Utils.Test.Attributes.TestCaseClasses
+{
+ internal class ClassWithPropertyWithoutDynamicVisibleAttribute
+ {
+ public double Property { get; set; }
+ }
+
+ internal class InvalidClassWithDynamicVisiblePropertyButNoValidationMethod
+ {
+ [DynamicVisible]
+ public double Property { get; set; }
+ }
+
+ internal class InvalidClassWithDynamicVisiblePropertyAndMultipleValidationMethod
+ {
+ [DynamicVisible]
+ public double Property { get; set; }
+
+ [DynamicVisibleValidationMethod]
+ public bool IsDynamicReadOnly1(string propertyName)
+ {
+ return true;
+ }
+
+ [DynamicVisibleValidationMethod]
+ public bool IsDynamicReadOnly2(string propertyName)
+ {
+ return false;
+ }
+ }
+
+ internal class InvalidClassWithDynamicVisiblePropertyButValidationMethodReturnsIncorrectValueType
+ {
+ [DynamicVisible]
+ public double Property { get; set; }
+
+ [DynamicVisibleValidationMethod]
+ public int IsDynamicReadOnly(string propertyName)
+ {
+ return 0;
+ }
+ }
+
+ internal class InvalidClassWithDynamicVisiblePropertyButValidationMethodNotOneArgument
+ {
+ [DynamicVisible]
+ public double Property { get; set; }
+
+ [DynamicVisibleValidationMethod]
+ public bool IsDynamicReadOnly(object o, string propertyName)
+ {
+ return true;
+ }
+ }
+
+ internal class InvalidClassWithDynamicVisiblePropertyButValidationMethodArgumentNotString
+ {
+ [DynamicVisible]
+ public double Property { get; set; }
+
+ [DynamicVisibleValidationMethod]
+ public bool IsDynamicReadOnly(object o)
+ {
+ return true;
+ }
+ }
+
+ internal class ClassWithDynamicVisibleProperty
+ {
+ private readonly bool isVisible;
+
+ public ClassWithDynamicVisibleProperty(bool isVisible)
+ {
+ this.isVisible = isVisible;
+ }
+
+ [DynamicVisible]
+ public double Property { get; set; }
+
+ [DynamicVisibleValidationMethod]
+ public bool IsDynamicVisible(string propertyName)
+ {
+ return isVisible;
+ }
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -87,8 +87,11 @@
+
+
+
Index: Core/Plugins/src/Core.Plugins.SharpMapGis.Gui/Forms/VectorLayerAttributeTableView.cs
===================================================================
diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Core/Plugins/src/Core.Plugins.SharpMapGis.Gui/Forms/VectorLayerAttributeTableView.cs (.../VectorLayerAttributeTableView.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca)
+++ Core/Plugins/src/Core.Plugins.SharpMapGis.Gui/Forms/VectorLayerAttributeTableView.cs (.../VectorLayerAttributeTableView.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -185,7 +185,7 @@
var rowObject = rowObjects[dataSourceIndexByRowIndex];
- return DynamicReadOnlyAttribute.IsDynamicReadOnly(rowObject, c.Column.Name);
+ return DynamicReadOnlyAttribute.IsReadOnly(rowObject, c.Column.Name);
}
private void DataSourceFeaturesChanged(object sender, EventArgs e)
Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingCalculationGroupContextPropertiesTest.cs
===================================================================
diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -rb443ebc25f4853fa10df2a68d3fedab32c8e84f3
--- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingCalculationGroupContextPropertiesTest.cs (.../PipingCalculationGroupContextPropertiesTest.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944)
+++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PropertyClasses/PipingCalculationGroupContextPropertiesTest.cs (.../PipingCalculationGroupContextPropertiesTest.cs) (revision b443ebc25f4853fa10df2a68d3fedab32c8e84f3)
@@ -97,7 +97,7 @@
// Assert
Assert.AreEqual(1, namePropertyAttributes.OfType().Count());
- Assert.AreEqual(!nameIsEditable, DynamicReadOnlyAttribute.IsDynamicReadOnly(properties, propertyName));
+ Assert.AreEqual(!nameIsEditable, DynamicReadOnlyAttribute.IsReadOnly(properties, propertyName));
}
}
}
\ No newline at end of file