private GetParameter ( int parameterIndex ) : Microsoft.Scripting.Actions.Calls.ParameterWrapper | ||
parameterIndex | int | |
리턴 | Microsoft.Scripting.Actions.Calls.ParameterWrapper |
/// <summary> /// Creates a new list of ParameterWrappers for the generic method replacing the old parameters with the new ones. /// </summary> private static List <ParameterWrapper> CreateNewWrappers(MethodCandidate candidate, OverloadInfo newOverload, OverloadInfo oldOverload) { List <ParameterWrapper> newWrappers = new List <ParameterWrapper>(); for (int i = 0; i < candidate.ParameterCount; i++) { ParameterWrapper oldWrap = candidate.GetParameter(i); ParameterInfo pi = null; Type newType = oldWrap.Type; if (oldWrap.ParameterInfo != null) { pi = newOverload.Parameters[oldWrap.ParameterInfo.Position]; ParameterInfo oldParam = oldOverload.Parameters[oldWrap.ParameterInfo.Position]; if (oldParam.ParameterType == oldWrap.Type) { newType = pi.ParameterType; } else if (pi.ParameterType.IsByRef) { newType = pi.ParameterType.GetElementType(); if (oldParam.ParameterType.GetElementType() != oldWrap.Type) { Debug.Assert(CompilerHelpers.IsStrongBox(oldWrap.Type)); newType = typeof(StrongBox <>).MakeGenericType(newType); } } else { Debug.Assert(oldParam.ParameterType.GetElementType() == oldWrap.Type); newType = pi.ParameterType.GetElementType(); } } newWrappers.Add(new ParameterWrapper(pi, newType, oldWrap.Name, oldWrap.Flags)); } return(newWrappers); }
/// <summary> /// Returns a mapping from generic type parameter to the input DMOs which map to it. /// </summary> private static Dictionary <Type /*!*/, ArgumentInputs /*!*/> /*!*/ GetArgumentToInputMapping(MethodCandidate /*!*/ candidate, IList <DynamicMetaObject /*!*/> /*!*/ args) { Dictionary <Type, ArgumentInputs> inputs = new Dictionary <Type, ArgumentInputs>(); for (int curParam = 0; curParam < candidate.ParameterCount; curParam++) { ParameterWrapper param = candidate.GetParameter(curParam); if (param.IsParamsArray) { AddOneInput(inputs, args[curParam], param.Type.GetElementType()); } else if (param.IsByRef) { AddOneInput(inputs, args[curParam], param.ParameterInfo.ParameterType); } else { AddOneInput(inputs, args[curParam], param.Type); } } return(inputs); }
private bool TryConvertArguments(MethodCandidate candidate, ArgumentBinding namesBinding, NarrowingLevel narrowingLevel, out CallFailure failure) { Debug.Assert(_actualArguments.Count == candidate.ParameterCount); BitArray hasConversion = new BitArray(_actualArguments.Count); bool success = true; for (int i = 0; i < _actualArguments.Count; i++) { success &= (hasConversion[i] = CanConvertFrom(_actualArguments[i].GetLimitType(), _actualArguments[i], candidate.GetParameter(i, namesBinding), narrowingLevel)); } if (!success) { var conversionResults = new ConversionResult[_actualArguments.Count]; for (int i = 0; i < _actualArguments.Count; i++) { conversionResults[i] = new ConversionResult(_actualArguments[i].Value, _actualArguments[i].GetLimitType(), candidate.GetParameter(i, namesBinding).Type, !hasConversion[i]); } failure = new CallFailure(candidate, conversionResults); } else { failure = null; } return success; }
private bool TryConvertCollapsedArguments(MethodCandidate candidate, NarrowingLevel narrowingLevel, out CallFailure failure) { Debug.Assert(_actualArguments.CollapsedCount > 0); // There must be at least one expanded parameter preceding splat index (see MethodBinder.GetSplatLimits): ParameterWrapper parameter = candidate.GetParameter(_actualArguments.SplatIndex - 1); Debug.Assert(parameter.ParameterInfo != null && CompilerHelpers.IsParamArray(parameter.ParameterInfo)); for (int i = 0; i < _actualArguments.CollapsedCount; i++) { object value = GetCollapsedArgumentValue(i); Type argType = CompilerHelpers.GetType(value); if (!CanConvertFrom(argType, null, parameter, narrowingLevel)) { failure = new CallFailure(candidate, new[] { new ConversionResult(value, argType, parameter.Type, false) }); return false; } } failure = null; return true; }
/// <summary> /// Returns a mapping from generic type parameter to the input DMOs which map to it. /// </summary> private static Dictionary<Type/*!*/, ArgumentInputs/*!*/>/*!*/ GetArgumentToInputMapping(MethodCandidate/*!*/ candidate, IList<DynamicMetaObject/*!*/>/*!*/ args) { Dictionary<Type, ArgumentInputs> inputs = new Dictionary<Type, ArgumentInputs>(); for (int curParam = 0; curParam < candidate.ParameterCount; curParam++) { ParameterWrapper param = candidate.GetParameter(curParam); if (param.IsParamsArray) { AddOneInput(inputs, args[curParam], param.Type.GetElementType()); } else if (param.IsByRef) { AddOneInput(inputs, args[curParam], param.ParameterInfo.ParameterType); } else { AddOneInput(inputs, args[curParam], param.Type); } } return inputs; }
/// <summary> /// Creates a new list of ParameterWrappers for the generic method replacing the old parameters with the new ones. /// </summary> private static List<ParameterWrapper> CreateNewWrappers(MethodCandidate candidate, OverloadInfo newOverload, OverloadInfo oldOverload) { List<ParameterWrapper> newWrappers = new List<ParameterWrapper>(); for (int i = 0; i < candidate.ParameterCount; i++) { ParameterWrapper oldWrap = candidate.GetParameter(i); ParameterInfo pi = null; Type newType = oldWrap.Type; if (oldWrap.ParameterInfo != null) { pi = newOverload.Parameters[oldWrap.ParameterInfo.Position]; ParameterInfo oldParam = oldOverload.Parameters[oldWrap.ParameterInfo.Position]; if (oldParam.ParameterType == oldWrap.Type) { newType = pi.ParameterType; } else if (pi.ParameterType.IsByRef) { newType = pi.ParameterType.GetElementType(); if (oldParam.ParameterType.GetElementType() != oldWrap.Type) { Debug.Assert(CompilerHelpers.IsStrongBox(oldWrap.Type)); newType = typeof(StrongBox<>).MakeGenericType(newType); } } else { Debug.Assert(oldParam.ParameterType.GetElementType() == oldWrap.Type); newType = pi.ParameterType.GetElementType(); } } newWrappers.Add(new ParameterWrapper(pi, newType, oldWrap.Name, oldWrap.Flags)); } return newWrappers; }
public ParameterWrapper GetParameter(int argumentIndex) { return(Method.GetParameter(argumentIndex, ArgumentBinding)); }
/// <summary> /// Returns a mapping from generic type parameter to the input DMOs which map to it. /// </summary> private static Dictionary<Type/*!*/, ArgumentInputs/*!*/>/*!*/ GetArgumentToInputMapping(MethodCandidate/*!*/ wrappers, IList<DynamicMetaObject/*!*/>/*!*/ args) { Dictionary<Type, ArgumentInputs> inputs = new Dictionary<Type, ArgumentInputs>(); for (int curParam = 0; curParam < wrappers.ParameterCount; curParam++) { if (wrappers.GetParameter(curParam).IsParamsArray) { AddOneInput(inputs, args[curParam], wrappers.GetParameter(curParam).Type.GetElementType()); } else { AddOneInput(inputs, args[curParam], wrappers.GetParameter(curParam).Type); } } return inputs; }
/// <summary> /// Creates a new list of ParameterWrappers for the generic method replacing the old parameters with the new ones. /// </summary> private static List<ParameterWrapper> CreateNewWrappers(MethodCandidate candidate, ParameterInfo[] newParams, ParameterInfo[] oldParams) { List<ParameterWrapper> newWrappers = new List<ParameterWrapper>(); for (int i = 0; i < candidate.ParameterCount; i++) { ParameterWrapper oldWrap = candidate.GetParameter(i); ParameterInfo pi = null; Type newType = oldWrap.Type; if (oldWrap.ParameterInfo != null) { pi = newParams[oldWrap.ParameterInfo.Position]; ParameterInfo oldParam = oldParams[oldWrap.ParameterInfo.Position]; if (oldParam.ParameterType == oldWrap.Type) { newType = pi.ParameterType; } else { Debug.Assert(oldParam.ParameterType.GetElementType() == oldWrap.Type); newType = pi.ParameterType.GetElementType(); } } newWrappers.Add(new ParameterWrapper(pi, newType, oldWrap.Name, oldWrap.ProhibitNull, oldWrap.IsParamsArray, oldWrap.IsParamsDict, oldWrap.IsHidden)); } return newWrappers; }