public void CreatePropertyOrderMethod_ClassWithDynamicPropertyOrderProperty_ReturnResultFromEvaluationMethod(int propertyOrder)
        {
            // Setup
            var o = new ClassWithDynamicPropertyOrderProperty(propertyOrder);

            // Call
            DynamicPropertyOrderEvaluationMethodAttribute.PropertyOrder result = DynamicPropertyOrderEvaluationMethodAttribute.CreatePropertyOrderMethod(o);

            // Assert
            Assert.AreEqual(propertyOrder, result("Property"));
        }
Exemple #2
0
        /// <summary>
        /// Determines the order of the property.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="propertyName">The name of the property of <paramref name="obj"/>.</param>
        /// <returns>The order of the property.</returns>
        /// <exception cref="MissingMemberException">Thrown when <paramref name="propertyName"/>
        /// does not correspond to a public property of <paramref name="obj"/>.</exception>
        /// <exception cref="MissingMethodException">Thrown when there isn't a single method
        /// declared on <paramref name="obj"/> marked with <see cref="DynamicPropertyOrderEvaluationMethodAttribute"/>
        /// that is matching the signature defined by <see cref="DynamicPropertyOrderEvaluationMethodAttribute.PropertyOrder"/>.</exception>
        public static int PropertyOrder(object obj, string propertyName)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                return(0);
            }

            if (!IsPropertyDynamicOrdered(obj, propertyName))
            {
                return(0);
            }

            DynamicPropertyOrderEvaluationMethodAttribute.PropertyOrder propertyOrder = DynamicPropertyOrderEvaluationMethodAttribute.CreatePropertyOrderMethod(obj);

            return(propertyOrder(propertyName));
        }