コード例 #1
0
        public void ShouldReadEmptyObject()
        {
            var properties = reader.PropertiesList(new object());

            Assert.That(properties, Is.Not.Null);
            Assert.That(properties.Count, Is.EqualTo(0));
        }
コード例 #2
0
        private IList <RouteValue> ReadParameters(MethodCallExpression methodCall)
        {
            var values = new List <RouteValue>();

            var attributeRecogniser = new AttributeRecogniser();
            var propertyReader      = new PropertyReader();

            var parameters = methodCall.Method.GetParameters();
            var arguments  = methodCall.Arguments;

            for (int i = 0; i < parameters.Length; i++)
            {
                var param            = parameters[i];
                var expectedValue    = GetExpectedValue(arguments[i]);
                var isFromBody       = attributeRecogniser.IsFromBody(param);
                var routeValueOrigin = isFromBody ? RouteValueOrigin.Body : RouteValueOrigin.Unknown;
                if (expectedValue != null || !isFromBody)
                {
                    if (propertyReader.IsSimpleType(param.ParameterType))
                    {
                        var resultValue = new RouteValue(param.Name, expectedValue, routeValueOrigin);
                        values.Add(resultValue);
                    }
                    else
                    {
                        var objectFieldValues = propertyReader.PropertiesList(expectedValue, routeValueOrigin)
                                                .Where(x => x.Value != null);
                        values.AddRange(objectFieldValues);
                    }
                }
            }

            return(values);
        }