public void GetParametersWrapsParameterInfos() { // Arrange ParameterInfo pInfo0 = typeof(ConcatController).GetMethod("Concat").GetParameters()[0]; ParameterInfo pInfo1 = typeof(ConcatController).GetMethod("Concat").GetParameters()[1]; ReflectedActionDescriptor ad = GetActionDescriptor(typeof(ConcatController).GetMethod("Concat")); // Act ParameterDescriptor[] pDescsFirstCall = ad.GetParameters(); ParameterDescriptor[] pDescsSecondCall = ad.GetParameters(); // Assert Assert.AreNotSame(pDescsFirstCall, pDescsSecondCall, "GetParameters() should return a new array on each invocation."); Assert.IsTrue(pDescsFirstCall.SequenceEqual(pDescsSecondCall), "Array elements were not equal."); Assert.AreEqual(2, pDescsFirstCall.Length); ReflectedParameterDescriptor pDesc0 = pDescsFirstCall[0] as ReflectedParameterDescriptor; ReflectedParameterDescriptor pDesc1 = pDescsFirstCall[1] as ReflectedParameterDescriptor; Assert.IsNotNull(pDesc0, "Parameter 0 should have been of type ReflectedParameterDescriptor."); Assert.AreSame(ad, pDesc0.ActionDescriptor, "Parameter 0 Action did not match."); Assert.AreSame(pInfo0, pDesc0.ParameterInfo, "Parameter 0 ParameterInfo did not match."); Assert.IsNotNull(pDesc1, "Parameter 1 should have been of type ReflectedParameterDescriptor."); Assert.AreSame(ad, pDesc1.ActionDescriptor, "Parameter 1 Action did not match."); Assert.AreSame(pInfo1, pDesc1.ParameterInfo, "Parameter 1 ParameterInfo did not match."); }
public void GetParametersWrapsParameterInfos() { // Arrange ParameterInfo pInfo0 = typeof(ConcatController).GetMethod("Concat").GetParameters()[0]; ParameterInfo pInfo1 = typeof(ConcatController).GetMethod("Concat").GetParameters()[1]; ReflectedActionDescriptor ad = GetActionDescriptor(typeof(ConcatController).GetMethod("Concat")); // Act ParameterDescriptor[] pDescsFirstCall = ad.GetParameters(); ParameterDescriptor[] pDescsSecondCall = ad.GetParameters(); // Assert Assert.NotSame(pDescsFirstCall, pDescsSecondCall); Assert.True(pDescsFirstCall.SequenceEqual(pDescsSecondCall)); Assert.Equal(2, pDescsFirstCall.Length); ReflectedParameterDescriptor pDesc0 = pDescsFirstCall[0] as ReflectedParameterDescriptor; ReflectedParameterDescriptor pDesc1 = pDescsFirstCall[1] as ReflectedParameterDescriptor; Assert.NotNull(pDesc0); Assert.Same(ad, pDesc0.ActionDescriptor); Assert.Same(pInfo0, pDesc0.ParameterInfo); Assert.NotNull(pDesc1); Assert.Same(ad, pDesc1.ActionDescriptor); Assert.Same(pInfo1, pDesc1.ParameterInfo); }
public FilterRegisterItem(Type controllerType, ReflectedActionDescriptor actionDescriptor, Type[] filterTypes) { ControllerType = controllerType; ActionDescriptor = actionDescriptor; _actionParameterDescriptors = ActionDescriptor.GetParameters(); FilterTypes = filterTypes; Filters = () => FilterTypes.Select(f => Activator.CreateInstance(f) as FilterAttribute); }
public FilterRegisterItem(Type controllerType, ReflectedActionDescriptor actionDescriptor, Type[] filterTypes) { ControllerType = controllerType; ActionDescriptor = actionDescriptor; _actionParameterDescriptors = ActionDescriptor.GetParameters(); FilterTypes = filterTypes; Filters = () => { if (FilterAttributesInstance != null) { return(FilterAttributesInstance); } return(FilterAttributesInstance = FilterTypes.Select(f => Activator.CreateInstance(f) as FilterAttribute).ToList()); }; }