Index: Core/Common/src/Core.Common.Gui/Attributes/DynamicPropertyOrderAttribute.cs =================================================================== diff -u -r85248172d4c431dd8c1c0a1a8934f6ca32c1016b -rc23e1b5f6b00b5c78641c3792fd59f178dbe3ad4 --- Core/Common/src/Core.Common.Gui/Attributes/DynamicPropertyOrderAttribute.cs (.../DynamicPropertyOrderAttribute.cs) (revision 85248172d4c431dd8c1c0a1a8934f6ca32c1016b) +++ Core/Common/src/Core.Common.Gui/Attributes/DynamicPropertyOrderAttribute.cs (.../DynamicPropertyOrderAttribute.cs) (revision c23e1b5f6b00b5c78641c3792fd59f178dbe3ad4) @@ -28,10 +28,10 @@ /// /// Marks property as a conditionally ordered property. When this attribute is declared /// on a property, the declaring class should have a public method marked with - /// to be used to evaluate the + /// to be used to evaluate the /// order of the property. /// - /// + /// /// /// This attribute provides a run-time alternative to . [AttributeUsage(AttributeTargets.Property)] @@ -46,8 +46,8 @@ /// When /// does not correspond to a public property of . /// When there isn't a single method - /// declared on marked with - /// that is matching the signature defined by . + /// declared on marked with + /// that is matching the signature defined by . public static int Order(object obj, string propertyName) { if (string.IsNullOrEmpty(propertyName)) @@ -60,7 +60,7 @@ return 0; } - var propertyOrder = DynamicPropertyOrderMethodAttribute.CreatePropertyOrderMethod(obj); + var propertyOrder = DynamicPropertyOrderEvaluationMethodAttribute.CreatePropertyOrderMethod(obj); return propertyOrder(propertyName); } Index: Core/Common/src/Core.Common.Gui/Attributes/DynamicPropertyOrderEvaluationMethodAttribute.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Gui/Attributes/DynamicPropertyOrderEvaluationMethodAttribute.cs (revision 0) +++ Core/Common/src/Core.Common.Gui/Attributes/DynamicPropertyOrderEvaluationMethodAttribute.cs (revision c23e1b5f6b00b5c78641c3792fd59f178dbe3ad4) @@ -0,0 +1,112 @@ +// 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.Linq; +using System.Reflection; +using CoreCommonGuiResources = Core.Common.Gui.Properties.Resources; + +namespace Core.Common.Gui.Attributes +{ + /// + /// Marks a method to be used to determine the order of a property. The method + /// should be public and have the signature of . + /// + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class DynamicPropertyOrderEvaluationMethodAttribute : Attribute + { + /// + /// Required method signature when marking a method with . + /// + /// The name of the property to be checked. + /// The order of the property. + public delegate int PropertyOrder(string propertyName); + + /// + /// Creates a delegate that can be used to determine the order of a property. + /// + /// The object instance declaring the evaluation method. + /// The delegate. + /// When there isn't a single method + /// declared on marked with + /// that is matching the signature defined by . + public static PropertyOrder CreatePropertyOrderMethod(object target) + { + var methodInfo = GetPropertyOrderMethod(target); + ValidateMethodInfo(methodInfo); + return CreatePropertyOrderDelegate(target, methodInfo); + } + + private static PropertyOrder CreatePropertyOrderDelegate(object target, MethodInfo methodInfo) + { + return (PropertyOrder) Delegate.CreateDelegate(typeof(PropertyOrder), target, methodInfo); + } + + private static void ValidateMethodInfo(MethodInfo methodInfo) + { + if (methodInfo.ReturnType != typeof(int)) + { + var message = string.Format(CoreCommonGuiResources.DynamicPropertyOrderEvaluationMethod_must_return_int_on_Class_0_, + methodInfo.DeclaringType); + throw new MissingMethodException(message); + } + + ParameterInfo[] parameterInfos = methodInfo.GetParameters(); + if (parameterInfos.Length != 1) + { + var message = string.Format(CoreCommonGuiResources.DynamicPropertyOrderEvaluationMethod_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(CoreCommonGuiResources.DynamicPropertyOrderEvaluationMethod_must_have_string_argument_on_Class_0_, + methodInfo.DeclaringType); + throw new MissingMethodException(message); + } + } + + private static MethodInfo GetPropertyOrderMethod(object obj) + { + var propertyOrderMethods = obj.GetType().GetMethods() + .Where(methodInfo => IsDefined(methodInfo, typeof(DynamicPropertyOrderEvaluationMethodAttribute))) + .ToArray(); + + if (propertyOrderMethods.Length == 0) + { + var message = string.Format(CoreCommonGuiResources.DynamicPropertyOrderEvaluationMethod_not_found_or_not_public_on_Class_0_, + obj.GetType()); + throw new MissingMethodException(message); + } + + if (propertyOrderMethods.Length > 1) + { + var message = string.Format(CoreCommonGuiResources.DynamicPropertyOrderEvaluationMethod_only_one_allowed_per_Class_0_, + obj.GetType()); + throw new MissingMethodException(message); + } + + return propertyOrderMethods[0]; + } + } +} \ No newline at end of file Fisheye: Tag c23e1b5f6b00b5c78641c3792fd59f178dbe3ad4 refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Gui/Attributes/DynamicPropertyOrderMethodAttribute.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj =================================================================== diff -u -rd4d24f72de2e86b7215351ed29e1debb8dd1de0d -rc23e1b5f6b00b5c78641c3792fd59f178dbe3ad4 --- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision d4d24f72de2e86b7215351ed29e1debb8dd1de0d) +++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision c23e1b5f6b00b5c78641c3792fd59f178dbe3ad4) @@ -98,7 +98,7 @@ - + Index: Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs =================================================================== diff -u -rd4d24f72de2e86b7215351ed29e1debb8dd1de0d -rc23e1b5f6b00b5c78641c3792fd59f178dbe3ad4 --- Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d4d24f72de2e86b7215351ed29e1debb8dd1de0d) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c23e1b5f6b00b5c78641c3792fd59f178dbe3ad4) @@ -405,48 +405,48 @@ } /// - /// Looks up a localized string similar to DynamicPropertyOrderMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}.. + /// Looks up a localized string similar to DynamicPropertyOrderEvaluationMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}.. /// - public static string DynamicPropertyOrderMethod_incorrect_argument_count_must_be_one_string_argument_on_Class_0_ { + public static string DynamicPropertyOrderEvaluationMethod_incorrect_argument_count_must_be_one_string_argument_on_Class_0_ { get { - return ResourceManager.GetString("DynamicPropertyOrderMethod_incorrect_argument_count_must_be_one_string_argument_o" + - "n_Class_0_", resourceCulture); + return ResourceManager.GetString("DynamicPropertyOrderEvaluationMethod_incorrect_argument_count_must_be_one_string_" + + "argument_on_Class_0_", resourceCulture); } } /// - /// Looks up a localized string similar to Argument van DynamicPropertyOrderMethod moet van het type 'string' zijn. Klasse: {0}.. + /// Looks up a localized string similar to Argument van DynamicPropertyOrderEvaluationMethod moet van het type 'string' zijn. Klasse: {0}.. /// - public static string DynamicPropertyOrderMethod_must_have_string_argument_on_Class_0_ { + public static string DynamicPropertyOrderEvaluationMethod_must_have_string_argument_on_Class_0_ { get { - return ResourceManager.GetString("DynamicPropertyOrderMethod_must_have_string_argument_on_Class_0_", resourceCulture); + return ResourceManager.GetString("DynamicPropertyOrderEvaluationMethod_must_have_string_argument_on_Class_0_", resourceCulture); } } /// - /// Looks up a localized string similar to DynamicPropertyOrderMethod moet 'int' als 'return type' hebben. Klasse: {0}.. + /// Looks up a localized string similar to DynamicPropertyOrderEvaluationMethod moet 'int' als 'return type' hebben. Klasse: {0}.. /// - public static string DynamicPropertyOrderMethod_must_return_int_on_Class_0_ { + public static string DynamicPropertyOrderEvaluationMethod_must_return_int_on_Class_0_ { get { - return ResourceManager.GetString("DynamicPropertyOrderMethod_must_return_int_on_Class_0_", resourceCulture); + return ResourceManager.GetString("DynamicPropertyOrderEvaluationMethod_must_return_int_on_Class_0_", resourceCulture); } } /// - /// Looks up a localized string similar to DynamicPropertyOrderMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}.. + /// Looks up a localized string similar to DynamicPropertyOrderEvaluationMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}.. /// - public static string DynamicPropertyOrderMethod_not_found_or_not_public_on_Class_0_ { + public static string DynamicPropertyOrderEvaluationMethod_not_found_or_not_public_on_Class_0_ { get { - return ResourceManager.GetString("DynamicPropertyOrderMethod_not_found_or_not_public_on_Class_0_", resourceCulture); + return ResourceManager.GetString("DynamicPropertyOrderEvaluationMethod_not_found_or_not_public_on_Class_0_", resourceCulture); } } /// - /// Looks up a localized string similar to Slechts één DynamicPropertyOrderMethod toegestaan per klasse: {0}.. + /// Looks up a localized string similar to Slechts één DynamicPropertyOrderEvaluationMethod toegestaan per klasse: {0}.. /// - public static string DynamicPropertyOrderMethod_only_one_allowed_per_Class_0_ { + public static string DynamicPropertyOrderEvaluationMethod_only_one_allowed_per_Class_0_ { get { - return ResourceManager.GetString("DynamicPropertyOrderMethod_only_one_allowed_per_Class_0_", resourceCulture); + return ResourceManager.GetString("DynamicPropertyOrderEvaluationMethod_only_one_allowed_per_Class_0_", resourceCulture); } } Index: Core/Common/src/Core.Common.Gui/Properties/Resources.resx =================================================================== diff -u -rd4d24f72de2e86b7215351ed29e1debb8dd1de0d -rc23e1b5f6b00b5c78641c3792fd59f178dbe3ad4 --- Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision d4d24f72de2e86b7215351ed29e1debb8dd1de0d) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision c23e1b5f6b00b5c78641c3792fd59f178dbe3ad4) @@ -478,20 +478,20 @@ Slechts één DynamicVisibleValidationMethod toegestaan per klasse: {0}. - - DynamicPropertyOrderMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}. + + DynamicPropertyOrderEvaluationMethod niet gevonden (of geen 'public' toegankelijkheid). Klasse: {0}. - - Slechts één DynamicPropertyOrderMethod toegestaan per klasse: {0}. + + Slechts één DynamicPropertyOrderEvaluationMethod toegestaan per klasse: {0}. - - DynamicPropertyOrderMethod moet 'int' als 'return type' hebben. Klasse: {0}. + + DynamicPropertyOrderEvaluationMethod moet 'int' als 'return type' hebben. Klasse: {0}. - - DynamicPropertyOrderMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}. + + DynamicPropertyOrderEvaluationMethod heeft een incorrect aantal argumenten. Zou er één moeten zijn. Klasse: {0}. - - Argument van DynamicPropertyOrderMethod moet van het type 'string' zijn. Klasse: {0}. + + Argument van DynamicPropertyOrderEvaluationMethod moet van het type 'string' zijn. Klasse: {0}. Het is niet gelukt om het Ringtoetsproject te laden.