private void MapParameterReduceByRef(ParameterInfo pi) { Debug.Assert(_returnArgs != null); // See KeywordArgBuilder.BuilderExpectsSingleParameter int indexForArgBuilder = 0; int nameIndex = -1; if (!pi.IsOutParameter()) { nameIndex = _argNames.IndexOf(pi.Name); if (nameIndex == -1) { indexForArgBuilder = _argIndex++; } } ArgBuilder ab; if (pi.IsOutParameter()) { _returnArgs.Add(_arguments.Count); ab = new OutArgBuilder(pi); } else if (pi.ParameterType.IsByRef) { // if the parameter is marked as [In] it is not returned. if ((pi.Attributes & (ParameterAttributes.In | ParameterAttributes.Out)) != ParameterAttributes.In) { _returnArgs.Add(_arguments.Count); } _parameters.Add(new ParameterWrapper(pi, pi.ParameterType.GetElementType(), pi.Name, ParameterBindingFlags.None)); ab = new ReturnReferenceArgBuilder(pi, indexForArgBuilder); } else { ab = AddSimpleParameterMapping(pi, indexForArgBuilder); } if (nameIndex == -1) { _arguments.Add(ab); } else { Debug.Assert(KeywordArgBuilder.BuilderExpectsSingleParameter(ab)); _arguments.Add(new KeywordArgBuilder(ab, _argNames.Count, nameIndex)); } }
/// <summary> /// Maps out parameters to return args and ref parameters to ones that don't accept StrongBox. /// </summary> private void MapParameterReduceByRef(ParameterInfo pi) { Debug.Assert(_returnArgs != null); // TODO: // Is this reduction necessary? What if // 1) we had an implicit conversion StrongBox<T> -> T& and // 2) all out parameters were treated as optional StrongBox<T> parameters? (if not present we return the result in a return value) int indexForArgBuilder = 0; int nameIndex = -1; if (!pi.IsOutParameter()) { nameIndex = _argNames.IndexOf(pi.Name); if (nameIndex == -1) { indexForArgBuilder = _argIndex++; } } ArgBuilder ab; if (pi.IsOutParameter()) { _returnArgs.Add(_arguments.Count); ab = new OutArgBuilder(pi); } else if (pi.ParameterType.IsByRef) { // if the parameter is marked as [In] it is not returned. if ((pi.Attributes & (ParameterAttributes.In | ParameterAttributes.Out)) != ParameterAttributes.In) { _returnArgs.Add(_arguments.Count); } _parameters.Add(new ParameterWrapper(pi, pi.ParameterType.GetElementType(), pi.Name, ParameterBindingFlags.None)); ab = new ReturnReferenceArgBuilder(pi, indexForArgBuilder); } else { ab = AddSimpleParameterMapping(pi, indexForArgBuilder); } if (nameIndex == -1) { _arguments.Add(ab); } else { Debug.Assert(KeywordArgBuilder.BuilderExpectsSingleParameter(ab)); _arguments.Add(new KeywordArgBuilder(ab, _argNames.Count, nameIndex)); } }