Junior.Route.AutoRouting.ResponseMappers.ParameterValueRetriever.GetParameterValuesAsync C# (CSharp) Method

GetParameterValuesAsync() public method

public GetParameterValuesAsync ( System.Web.HttpContextBase context, Type type, MethodInfo method ) : Task>
context System.Web.HttpContextBase
type System.Type
method System.Reflection.MethodInfo
return Task>
		public async Task<IEnumerable<object>> GetParameterValuesAsync(HttpContextBase context, Type type, MethodInfo method)
		{
			context.ThrowIfNull("context");
			type.ThrowIfNull("type");
			method.ThrowIfNull("method");

			ParameterInfo[] parameterInfos = method.GetParameters();
			var parameterValues = new List<object>();

			foreach (ParameterInfo parameterInfo in parameterInfos)
			{
				Type parameterType = parameterInfo.ParameterType;
				string parameterName = parameterInfo.Name;
				Type currentParameterType = parameterType;

				do
				{
					bool mapped = false;

					foreach (IParameterMapper parameterMapper in _parameterMappers)
					{
						if (!await parameterMapper.CanMapTypeAsync(context, parameterType))
						{
							continue;
						}
						MapResult mapResult = await parameterMapper.MapAsync(context, type, method, parameterInfo);

						if (mapResult.ResultType == MapResultType.ValueNotMapped)
						{
							continue;
						}

						parameterValues.Add(mapResult.Value);
						mapped = true;
						break;
					}
					if (mapped)
					{
						break;
					}

					currentParameterType = currentParameterType.BaseType;
				} while (currentParameterType != null);

				if (currentParameterType == null)
				{
					throw new ApplicationException(
						String.Format(
							"No request parameter mapper was found for parameter '{0} {1}' of {2}.{3}.",
							parameterType.FullName,
							parameterName,
							type.FullName,
							method.Name));
				}
			}

			return parameterValues;
		}
	}

Usage Example

			public void SetUp()
			{
				_mapper1 = MockRepository.GenerateMock<IParameterMapper>();
				_mapper1.Stub(arg => arg.CanMapTypeAsync(Arg<HttpContextBase>.Is.Anything, Arg<Type>.Is.Anything)).Return(false.AsCompletedTask());
				_mapper2 = MockRepository.GenerateMock<IParameterMapper>();
				_mapper2.Stub(arg => arg.CanMapTypeAsync(Arg<HttpContextBase>.Is.Anything, Arg<Type>.Is.Anything)).Return(true.AsCompletedTask());
				_mapper2
					.Stub(arg => arg.MapAsync(Arg<HttpContextBase>.Is.Anything, Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything, Arg<ParameterInfo>.Is.Anything))
					.WhenCalled(arg => arg.ReturnValue = (MapResult.ValueMapped(100)).AsCompletedTask())
					.Return(null);
				_mapper3 = MockRepository.GenerateMock<IParameterMapper>();
				_mapper3.Stub(arg => arg.CanMapTypeAsync(Arg<HttpContextBase>.Is.Anything, Arg<Type>.Is.Anything)).Return(false.AsCompletedTask());
				_retriever = new ParameterValueRetriever(new[] { _mapper1, _mapper2, _mapper3 });
				_context = MockRepository.GenerateMock<HttpContextBase>();
				_values = _retriever.GetParameterValuesAsync(_context, typeof(Endpoint), typeof(Endpoint).GetMethod("Method")).Result;
			}
All Usage Examples Of Junior.Route.AutoRouting.ResponseMappers.ParameterValueRetriever::GetParameterValuesAsync