/// <summary> /// Gets the position of the specified <see cref="FuncConstructorArgument"/> relative to the /// other <see cref="FuncConstructorArgument"/> of the same type in the specified context. /// </summary> /// <param name="argument">The argument for which the position is calculated.</param> /// <param name="context">The context of the argument.</param> /// <param name="target">The target.</param> /// <returns> /// -1 if the parameter does not exist in the context or if another constructor argument applies for the target. /// Otherwise the position of the specified <see cref="FuncConstructorArgument"/> within the other <see cref="FuncConstructorArgument"/> /// of the same type contained in context.Parameters. /// </returns> public int GetPositionOfFuncConstructorArgument(FuncConstructorArgument argument, IContext context, ITarget target) { int currentPosition = 0; int position = -1; foreach (var constructorArgumentParameter in context.Parameters.OfType <IConstructorArgument>()) { var funcArgumentParameter = constructorArgumentParameter as FuncConstructorArgument; if (funcArgumentParameter != null) { if (ReferenceEquals(argument, funcArgumentParameter)) { position = currentPosition; } else { if (funcArgumentParameter.ArgumentType == target.Type) { currentPosition++; } } } else { if (constructorArgumentParameter.AppliesToTarget(context, target)) { return(-1); } } } return(position); }
/// <summary> /// Gets the position of the specified <see cref="FuncConstructorArgument"/> relative to the /// other <see cref="FuncConstructorArgument"/> of the same type in the specified context. /// </summary> /// <param name="argument">The argument for which the position is calculated.</param> /// <param name="context">The context of the argument.</param> /// <param name="target">The target.</param> /// <returns> /// -1 if the parameter does not exist in the context or if another constructor argument applies for the target. /// Otherwise the position of the specified <see cref="FuncConstructorArgument"/> within the other <see cref="FuncConstructorArgument"/> /// of the same type contained in context.Parameters. /// </returns> public int GetPositionOfFuncConstructorArgument(FuncConstructorArgument argument, IContext context, ITarget target) { int currentPosition = 0; int position = -1; foreach (var constructorArgumentParameter in context.Parameters.OfType<IConstructorArgument>()) { var funcArgumentParameter = constructorArgumentParameter as FuncConstructorArgument; if (funcArgumentParameter != null) { if (ReferenceEquals(argument, funcArgumentParameter)) { position = currentPosition; } else { if (funcArgumentParameter.ArgumentType == target.Type) { currentPosition++; } } } else { if (constructorArgumentParameter.AppliesToTarget(context, target)) { return -1; } } } return position; }