Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj =================================================================== diff -u -ree73eb1956b80d67caa6047be8dc97c223851350 -r0cc720a1127d4a67a8620e045eaed48d312f7972 --- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision ee73eb1956b80d67caa6047be8dc97c223851350) +++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 0cc720a1127d4a67a8620e045eaed48d312f7972) @@ -165,6 +165,7 @@ + Index: Core/Common/src/Core.Common.Gui/PropertyBag/ReadOnlyPropertyDescriptorDecorator.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Gui/PropertyBag/ReadOnlyPropertyDescriptorDecorator.cs (revision 0) +++ Core/Common/src/Core.Common.Gui/PropertyBag/ReadOnlyPropertyDescriptorDecorator.cs (revision 0cc720a1127d4a67a8620e045eaed48d312f7972) @@ -0,0 +1,177 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.ComponentModel; + +namespace Core.Common.Gui.PropertyBag +{ + /// + /// A decorator that forces + /// to true regardless of the wrapped . + /// + public class ReadOnlyPropertyDescriptorDecorator : PropertyDescriptor + { + private readonly PropertyDescriptor wrappedPropertyDescriptor; + + /// + /// Initializes a new instance of the class. + /// + /// The property descriptor to be wrapped. + public ReadOnlyPropertyDescriptorDecorator(PropertyDescriptor propertyDescriptor) : base(propertyDescriptor) + { + wrappedPropertyDescriptor = propertyDescriptor; + } + + public override bool IsReadOnly + { + get + { + return true; + } + } + + #region Methods and Properties delegates to wrapped property descriptor + + public override bool CanResetValue(object component) + { + return wrappedPropertyDescriptor.CanResetValue(component); + } + + public override object GetValue(object component) + { + return wrappedPropertyDescriptor.GetValue(component); + } + + public override void ResetValue(object component) + { + wrappedPropertyDescriptor.ResetValue(component); + } + + public override void SetValue(object component, object value) + { + wrappedPropertyDescriptor.SetValue(component, value); + } + + public override bool ShouldSerializeValue(object component) + { + return wrappedPropertyDescriptor.ShouldSerializeValue(component); + } + + public override AttributeCollection Attributes + { + get + { + return wrappedPropertyDescriptor.Attributes; + } + } + + public override string Category + { + get + { + return wrappedPropertyDescriptor.Category; + } + } + + public override Type ComponentType + { + get + { + return wrappedPropertyDescriptor.ComponentType; + } + } + + public override TypeConverter Converter + { + get + { + return wrappedPropertyDescriptor.Converter; + } + } + + public override string Description + { + get + { + return wrappedPropertyDescriptor.Description; + } + } + + public override bool DesignTimeOnly + { + get + { + return wrappedPropertyDescriptor.DesignTimeOnly; + } + } + + public override string DisplayName + { + get + { + return wrappedPropertyDescriptor.DisplayName; + } + } + + public override bool IsBrowsable + { + get + { + return wrappedPropertyDescriptor.IsBrowsable; + } + } + + public override bool IsLocalizable + { + get + { + return wrappedPropertyDescriptor.IsLocalizable; + } + } + + public override string Name + { + get + { + return wrappedPropertyDescriptor.Name; + } + } + + public override Type PropertyType + { + get + { + return wrappedPropertyDescriptor.PropertyType; + } + } + + public override bool SupportsChangeEvents + { + get + { + return wrappedPropertyDescriptor.SupportsChangeEvents; + } + } + + #endregion + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj =================================================================== diff -u -ree73eb1956b80d67caa6047be8dc97c223851350 -r0cc720a1127d4a67a8620e045eaed48d312f7972 --- Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision ee73eb1956b80d67caa6047be8dc97c223851350) +++ Core/Common/test/Core.Common.Gui.Test/Core.Common.Gui.Test.csproj (.../Core.Common.Gui.Test.csproj) (revision 0cc720a1127d4a67a8620e045eaed48d312f7972) @@ -149,6 +149,7 @@ + @@ -188,6 +189,9 @@ + + Copying.Lesser.licenseheader + Index: Core/Common/test/Core.Common.Gui.Test/PropertyBag/ReadOnlyPropertyDescriptorDecoratorTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Gui.Test/PropertyBag/ReadOnlyPropertyDescriptorDecoratorTest.cs (revision 0) +++ Core/Common/test/Core.Common.Gui.Test/PropertyBag/ReadOnlyPropertyDescriptorDecoratorTest.cs (revision 0cc720a1127d4a67a8620e045eaed48d312f7972) @@ -0,0 +1,180 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.ComponentModel; +using Core.Common.Gui.PropertyBag; +using NUnit.Framework; + +namespace Core.Common.Gui.Test.PropertyBag +{ + [TestFixture] + public class ReadOnlyPropertyDescriptorDecoratorTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var target = new SomeTestClass(); + var properties = TypeDescriptor.GetProperties(target); + + PropertyDescriptor getSetProperty = properties[0]; + + // Precondtion: + Assert.IsFalse(getSetProperty.IsReadOnly); + + // Call + var readonlyPropertyDescriptor = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); + + // Assert + Assert.IsInstanceOf(readonlyPropertyDescriptor); + Assert.IsTrue(readonlyPropertyDescriptor.IsReadOnly); + + Assert.AreEqual(getSetProperty.ComponentType, readonlyPropertyDescriptor.ComponentType); + Assert.AreEqual(getSetProperty.PropertyType, readonlyPropertyDescriptor.PropertyType); + Assert.AreEqual(getSetProperty.Attributes, readonlyPropertyDescriptor.Attributes); + Assert.AreEqual(getSetProperty.Category, readonlyPropertyDescriptor.Category); + Assert.AreEqual(getSetProperty.Converter, readonlyPropertyDescriptor.Converter); + Assert.AreEqual(getSetProperty.Description, readonlyPropertyDescriptor.Description); + Assert.AreEqual(getSetProperty.DesignTimeOnly, readonlyPropertyDescriptor.DesignTimeOnly); + Assert.AreEqual(getSetProperty.DisplayName, readonlyPropertyDescriptor.DisplayName); + Assert.AreEqual(getSetProperty.IsBrowsable, readonlyPropertyDescriptor.IsBrowsable); + Assert.AreEqual(getSetProperty.IsLocalizable, readonlyPropertyDescriptor.IsLocalizable); + Assert.AreEqual(getSetProperty.Name, readonlyPropertyDescriptor.Name); + Assert.AreEqual(getSetProperty.SerializationVisibility, readonlyPropertyDescriptor.SerializationVisibility); + Assert.AreEqual(getSetProperty.SupportsChangeEvents, readonlyPropertyDescriptor.SupportsChangeEvents); + } + + [Test] + public void CanResetValue_Always_DelegateToWrappedPropertyDescriptor() + { + // Setup + var component = new SomeTestClass(); + var properties = TypeDescriptor.GetProperties(component); + + PropertyDescriptor getSetProperty = properties[0]; + var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); + + // Call + var result = wrappedProperty.CanResetValue(component); + + // Assert + Assert.AreEqual(getSetProperty.CanResetValue(component), result); + } + + [Test] + public void GetValue_Always_DelegateToWrappedPropertyDescriptor() + { + // Setup + var component = new SomeTestClass + { + SomeEditableProperty = 1.1 + }; + + var properties = TypeDescriptor.GetProperties(component); + PropertyDescriptor getSetProperty = properties[0]; + + var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); + + // Call + var result = wrappedProperty.GetValue(component); + + // Assert + Assert.AreEqual(getSetProperty.GetValue(component), result); + Assert.AreEqual(component.SomeEditableProperty, result); + } + + [Test] + public void ResetValue_Always_DelegateToWrappedPropertyDescriptor() + { + // Setup + const double originalPropertyValue = 1.1; + var component = new SomeTestClass + { + SomeEditableProperty = originalPropertyValue + }; + + var properties = TypeDescriptor.GetProperties(component); + PropertyDescriptor getSetProperty = properties[0]; + + getSetProperty.ResetValue(component); + var expectedPropertyValueAfterReset = component.SomeEditableProperty; + + var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); + component.SomeEditableProperty = originalPropertyValue; + + // Call + wrappedProperty.ResetValue(component); + + // Assert + Assert.AreEqual(expectedPropertyValueAfterReset, component.SomeEditableProperty); + } + + [Test] + public void SetValue_Always_DelegateToWrappedPropertyDescriptor() + { + // Setup + const double originalPropertyValue = 1.1; + const double newValue = 2.2; + var component = new SomeTestClass + { + SomeEditableProperty = originalPropertyValue + }; + + var properties = TypeDescriptor.GetProperties(component); + PropertyDescriptor getSetProperty = properties[0]; + + getSetProperty.SetValue(component, newValue); + var expectedPropertyValueAfterSet = component.SomeEditableProperty; + + var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); + component.SomeEditableProperty = originalPropertyValue; + + // Call + wrappedProperty.SetValue(component, newValue); + + // Assert + Assert.AreEqual(expectedPropertyValueAfterSet, component.SomeEditableProperty); + } + + [Test] + public void ShouldSerializeValue_Always_DelegateToWrappedPropertyDescriptor() + { + // Setup + var component = new SomeTestClass(); + var properties = TypeDescriptor.GetProperties(component); + + PropertyDescriptor getSetProperty = properties[0]; + var wrappedProperty = new ReadOnlyPropertyDescriptorDecorator(getSetProperty); + + // Call + var result = wrappedProperty.ShouldSerializeValue(component); + + // Assert + Assert.AreEqual(getSetProperty.ShouldSerializeValue(component), result); + } + + private class SomeTestClass + { + [ReadOnly(false)] + public double SomeEditableProperty { get; set; } + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj =================================================================== diff -u -r1a0c6531ce4051b92eb6d2b770392f7c226159fa -r0cc720a1127d4a67a8620e045eaed48d312f7972 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 1a0c6531ce4051b92eb6d2b770392f7c226159fa) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Ringtoets.Piping.Forms.csproj (.../Ringtoets.Piping.Forms.csproj) (revision 0cc720a1127d4a67a8620e045eaed48d312f7972) @@ -80,7 +80,6 @@ - Fisheye: Tag 0cc720a1127d4a67a8620e045eaed48d312f7972 refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Forms/TypeConverters/PropertyDescriptors/ReadOnlyPropertyDescriptorDecorator.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 0cc720a1127d4a67a8620e045eaed48d312f7972 refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/PropertyDescriptors/ReadOnlyPropertyDescriptorDecoratorTest.cs'. Fisheye: No comparison available. Pass `N' to diff?