当前位置: 首页>>代码示例>>C#>>正文


C# Calls.ParameterWrapper类代码示例

本文整理汇总了C#中Microsoft.Scripting.Actions.Calls.ParameterWrapper的典型用法代码示例。如果您正苦于以下问题:C# ParameterWrapper类的具体用法?C# ParameterWrapper怎么用?C# ParameterWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParameterWrapper类属于Microsoft.Scripting.Actions.Calls命名空间,在下文中一共展示了ParameterWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanConvertFrom

        public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArg, ParameterWrapper toParameter, NarrowingLevel level) {
            if ((fromType == typeof(List) || fromType.IsSubclassOf(typeof(List)))) {
                if (toParameter.Type.IsGenericType() &&
                    toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>) &&
                    (toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false) ||
                     toParameter.ParameterInfo.IsDefined(typeof(BytesConversionNoStringAttribute), false))) {
                    return false;
                }
            } else if (fromType == typeof(string)) {
                if (toParameter.Type == typeof(IList<byte>) &&
                    !Binder.Context.PythonOptions.Python30 &&
                    toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false)) {
                    // string -> byte array, we allow this in Python 2.6
                    return true;
                }
            } else if (fromType == typeof(Bytes)) {
                if (toParameter.Type == typeof(string) &&
                    !Binder.Context.PythonOptions.Python30 &&
                    toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false)) {
                    return true;
                }
            }

            return base.CanConvertFrom(fromType, fromArg, toParameter, level);
        }
开发者ID:kotikus,项目名称:iron,代码行数:25,代码来源:PythonOverloadResolver.cs

示例2: CanConvertFrom

        public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArgument, ParameterWrapper toParameter, NarrowingLevel level)
        {
            if (toParameter.Type == typeof(string) && (level == NarrowingLevel.Three || level == NarrowingLevel.All))
                return true;

            if (toParameter.IsParamsArray == true && typeof(IList<object>).IsAssignableFrom(fromType))
            {
                var toType = toParameter.Type.GetElementType();
                var list = (IList<object>)fromArgument.Value;
                for(var i = 0; i < list.Count; i++)
                {
                    var itm = list[i];
                    var argExp = Expression.Call(
                        Expression.Convert(fromArgument.Expression, fromArgument.LimitType),
                        (typeof(IList<object>).GetMethod("get_Item")),
                        Expression.Constant(i, typeof(int))
                    );
                    var arg = new DynamicMetaObject(
                        argExp,
                        fromArgument.Restrictions,
                        itm
                    );
                    if(!CanConvertFrom(itm.GetType(), arg, new ParameterWrapper(null, toType, null, ParameterBindingFlags.None), level))
                        return false;
                }
                return true;
            }

            return base.CanConvertFrom(fromType, fromArgument, toParameter, level);
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:30,代码来源:OverloadResolver.cs

示例3: CanConvertFrom

        public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArgument, ParameterWrapper toParameter, NarrowingLevel level)
        {
            if (level >= NarrowingLevel.Two)
            {
                if (toParameter.Type == typeof(string))
                    return true;
            }

            return base.CanConvertFrom(fromType, fromArgument, toParameter, level);
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:10,代码来源:TotemOverloadResolver.cs

示例4: CanConvertFrom

        public override bool CanConvertFrom(Type fromType, ParameterWrapper toParameter, NarrowingLevel level) {
            if ((fromType == typeof(List) || fromType.IsSubclassOf(typeof(List))) && 
                toParameter.Type.IsGenericType && 
                toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>)) {
                if (toParameter.ParameterInfo.IsDefined(typeof(ProhibitGenericListConversionAttribute), false)) {
                    return false;
                }
            }

            return base.CanConvertFrom(fromType, toParameter, level);
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:11,代码来源:PythonOverloadResolver.cs

示例5: MethodCandidate

        internal MethodCandidate(OverloadResolver resolver, MethodBase method, List<ParameterWrapper> parameters, ParameterWrapper paramsDict,
            ReturnBuilder returnBuilder, ArgBuilder instanceBuilder, IList<ArgBuilder> argBuilders) {

            Assert.NotNull(resolver, method, instanceBuilder, returnBuilder);
            Assert.NotNullItems(parameters);
            Assert.NotNullItems(argBuilders);

            _resolver = resolver;
            _method = method;
            _instanceBuilder = instanceBuilder;
            _argBuilders = argBuilders;
            _returnBuilder = returnBuilder;
            _parameters = parameters;
            _paramsDict = paramsDict;

            _paramsArrayIndex = ParameterWrapper.IndexOfParamsArray(parameters);

            parameters.TrimExcess();
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:19,代码来源:MethodCandidate.cs

示例6: MethodCandidate

        internal MethodCandidate(OverloadResolver resolver, OverloadInfo method, List<ParameterWrapper> parameters, ParameterWrapper paramsDict,
            ReturnBuilder returnBuilder, InstanceBuilder instanceBuilder, IList<ArgBuilder> argBuilders, Dictionary<DynamicMetaObject, BindingRestrictions> restrictions) {

            Assert.NotNull(resolver, method, instanceBuilder, returnBuilder);
            Assert.NotNullItems(parameters);
            Assert.NotNullItems(argBuilders);

            _resolver = resolver;
            _overload = method;
            _instanceBuilder = instanceBuilder;
            _argBuilders = argBuilders;
            _returnBuilder = returnBuilder;
            _parameters = parameters;
            _paramsDict = paramsDict;
            _restrictions = restrictions;

            _paramsArrayIndex = ParameterWrapper.IndexOfParamsArray(parameters);

            parameters.TrimExcess();
        }
开发者ID:hansdude,项目名称:Phalanger,代码行数:20,代码来源:MethodCandidate.cs

示例7: SelectBestConversionFor

 /// <summary>
 /// Selects the best (of two) candidates for conversion from actualType
 /// </summary>
 public virtual Candidate SelectBestConversionFor(DynamicMetaObject arg, ParameterWrapper candidateOne, ParameterWrapper candidateTwo, NarrowingLevel level) {
     return Candidate.Equivalent;
 }
开发者ID:apboyle,项目名称:ironruby,代码行数:6,代码来源:OverloadResolver.cs

示例8: GetPreferredParameter

        private static Candidate GetPreferredParameter(ParameterWrapper candidateOne, ParameterWrapper candidateTwo) {
            Assert.NotNull(candidateOne, candidateTwo);

            if (candidateOne._binder.ParametersEquivalent(candidateOne, candidateTwo)) {
                return Candidate.Equivalent;
            }

            Type t1 = candidateOne.Type;
            Type t2 = candidateTwo.Type;

            if (candidateOne._binder.CanConvertFrom(t2, candidateOne, NarrowingLevel.None)) {
                if (candidateOne._binder.CanConvertFrom(t1, candidateTwo, NarrowingLevel.None)) {
                    return Candidate.Ambiguous;
                } else {
                    return Candidate.Two;
                }
            }

            if (candidateOne._binder.CanConvertFrom(t1, candidateTwo, NarrowingLevel.None)) {
                return Candidate.One;
            }

            // Special additional rules to order numeric value types
            Candidate preferred = candidateOne._binder.PreferConvert(t1, t2);
            if (preferred.Chosen()) {
                return preferred;
            }

            preferred = candidateOne._binder.PreferConvert(t2, t1).TheOther();
            if (preferred.Chosen()) {
                return preferred;
            }

            return Candidate.Ambiguous;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:35,代码来源:ParameterWrapper.cs

示例9: MapParameter

        public void MapParameter(ParameterInfo pi) {
            int indexForArgBuilder;
            int nameIndex = _argNames.IndexOf(pi.Name);
            if (nameIndex == -1) {
                // positional argument, we simply consume the next argument
                indexForArgBuilder = _argIndex++;
            } else {
                // keyword argument, we just tell the simple arg builder to consume arg 0.
                // KeywordArgBuilder will then pass in the correct single argument based 
                // upon the actual argument number provided by the user.
                indexForArgBuilder = 0;
            }

            // if the parameter is default we need to build a default arg builder and then
            // build a reduced method at the end.  
            if (!CompilerHelpers.IsMandatoryParameter(pi)) {
                // We need to build the default builder even if we have a parameter for it already to
                // get good consistency of our error messages.  But consider a method like 
                // def foo(a=1, b=2) and the user calls it as foo(b=3). Then adding the default
                // value breaks an otherwise valid call.  This is because we only generate MethodCandidates
                // filling in the defaults from right to left (so the method - 1 arg requires a,
                // and the method minus 2 args requires b).  So we only add the default if it's 
                // a positional arg or we don't already have a default value.
                if (nameIndex == -1 || !_hasDefaults) {
                    _defaultArguments.Add(new DefaultArgBuilder(pi));
                    _hasDefaults = true;
                } else {
                    _defaultArguments.Add(null);
                }
            } else if (_defaultArguments.Count > 0) {
                // non-contigious default parameter
                _defaultArguments.Add(null);
            }

            ArgBuilder ab;
            if (pi.ParameterType.IsByRef) {
                _hasByRefOrOut = true;
                Type refType = typeof(StrongBox<>).MakeGenericType(pi.ParameterType.GetElementType());
                _parameters.Add(new ParameterWrapper(pi, refType, pi.Name, true, false, false, false));
                ab = new ReferenceArgBuilder(pi, refType, indexForArgBuilder);
            } else if (BinderHelpers.IsParamDictionary(pi)) {
                _paramsDict = new ParameterWrapper(pi);
                ab = new SimpleArgBuilder(pi, indexForArgBuilder);
            } else if (pi.Position == 0 && CompilerHelpers.IsExtension(pi.Member)) {
                _parameters.Add(new ParameterWrapper(pi, pi.ParameterType, pi.Name, true, false, false, true));
                ab = new SimpleArgBuilder(pi, indexForArgBuilder);
            } else {
                _hasByRefOrOut |= CompilerHelpers.IsOutParameter(pi);
                _parameters.Add(new ParameterWrapper(pi));
                ab = new SimpleArgBuilder(pi, indexForArgBuilder);
            }

            if (nameIndex == -1) {
                _arguments.Add(ab);
            } else {
                Debug.Assert(KeywordArgBuilder.BuilderExpectsSingleParameter(ab));
                _arguments.Add(new KeywordArgBuilder(ab, _argNames.Count, nameIndex));
            }
        }
开发者ID:teejayvanslyke,项目名称:ironruby,代码行数:59,代码来源:ParameterMapping.cs

示例10: HasExplicitProtocolConversion

 private bool HasExplicitProtocolConversion(ParameterWrapper/*!*/ parameter) {
     return
         parameter.ParameterInfo != null &&
         parameter.ParameterInfo.IsDefined(typeof(DefaultProtocolAttribute), false) &&
         !parameter.IsParamsArray; // default protocol doesn't apply on param-array/dict itself, only on the expanded parameters
 }
开发者ID:andreakn,项目名称:ironruby,代码行数:6,代码来源:RubyOverloadResolver.cs

示例11: CanConvertFrom

 /// <summary>
 /// Returns true if fromArg of type fromType can be assigned to toParameter with a conversion on given narrowing level.
 /// </summary>
 public override bool CanConvertFrom(Type/*!*/ fromType, DynamicMetaObject fromArg, ParameterWrapper/*!*/ toParameter, NarrowingLevel level) {
     return Converter.CanConvertFrom(fromArg, fromType, toParameter.Type, toParameter.ProhibitNull, level, 
         HasExplicitProtocolConversion(toParameter), _implicitProtocolConversions
     );
 }
开发者ID:andreakn,项目名称:ironruby,代码行数:8,代码来源:RubyOverloadResolver.cs

示例12: CanConvertFrom

        public override bool CanConvertFrom(Type/*!*/ fromType, ParameterWrapper/*!*/ toParameter, NarrowingLevel level) {
            Type toType = toParameter.Type;

            if (toType == fromType) {
                return true;
            }

            if (fromType == typeof(DynamicNull)) {
                if (toParameter.ProhibitNull) {
                    return false;
                }

                if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
                    return true;
                }

                if (!toType.IsValueType) {
                    return true;
                }
            }

            // blocks:
            if (fromType == typeof(MissingBlockParam)) {
                return toType == typeof(BlockParam) && !toParameter.ProhibitNull;
            }

            if (fromType == typeof(BlockParam) && toType == typeof(MissingBlockParam)) {
                return true;
            }

            // protocol conversions:
            if (toParameter.ParameterInfo != null && toParameter.ParameterInfo.IsDefined(typeof(DefaultProtocolAttribute), false) &&
                // default protocol doesn't apply on param-array/dict itself, only on the expanded parameters:
                !toParameter.IsParamsArray) {

                // any type is potentially convertible, except for nil if [NotNull] is used or the target type is a value type:
                return fromType != typeof(DynamicNull) || !(toParameter.ProhibitNull || toType.IsValueType);
            }

            if (Converter.CanConvertFrom(fromType, toType, level, _implicitProtocolConversions)) {
                return true;
            }

            return false;
        }
开发者ID:xerxesb,项目名称:ironruby,代码行数:45,代码来源:RubyOverloadResolver.cs

示例13: SelectBestConversionFor

        public override Candidate SelectBestConversionFor(DynamicMetaObject/*!*/ arg, ParameterWrapper/*!*/ candidateOne, 
            ParameterWrapper/*!*/ candidateTwo, NarrowingLevel level) {

            Type typeOne = candidateOne.Type;
            Type typeTwo = candidateTwo.Type;
            Type actualType = arg.GetLimitType();

            // if nil is passed as a block argument prefer BlockParam over missing block:
            if (actualType == typeof(DynamicNull)) {
                if (typeOne == typeof(BlockParam) && typeTwo == typeof(MissingBlockParam)) {
                    Debug.Assert(!candidateOne.ProhibitNull);
                    return Candidate.One;
                }

                if (typeOne == typeof(MissingBlockParam) && typeTwo == typeof(BlockParam)) {
                    Debug.Assert(!candidateTwo.ProhibitNull);
                    return Candidate.Two;
                }
            } else if (actualType == typeof(MissingBlockParam)) {
                if (typeOne == typeof(BlockParam) && typeTwo == typeof(MissingBlockParam)) {
                    return Candidate.Two;
                }

                if (typeOne == typeof(MissingBlockParam) && typeTwo == typeof(BlockParam)) {
                    return Candidate.One;
                }
            } else if (actualType == typeof(BlockParam)) {
                if (typeOne == typeof(BlockParam) && typeTwo == typeof(MissingBlockParam)) {
                    return Candidate.One;
                }

                if (typeOne == typeof(MissingBlockParam) && typeTwo == typeof(BlockParam)) {
                    return Candidate.Two;
                }

                if (typeOne == typeof(BlockParam) && typeTwo == typeof(BlockParam)) {
                    if (candidateOne.ProhibitNull) {
                        return Candidate.One;
                    } else if (candidateTwo.ProhibitNull) {
                        return Candidate.Two;
                    }
                }
            }
            return base.SelectBestConversionFor(arg, candidateOne, candidateTwo, level);
        }
开发者ID:gregmalcolm,项目名称:ironruby,代码行数:45,代码来源:RubyOverloadResolver.cs

示例14: AddSimpleParameterMapping

        private SimpleArgBuilder AddSimpleParameterMapping(ParameterInfo info, int index) {
            var param = CreateParameterWrapper(info);
            if (param.IsParamsDict) {
                _paramsDict = param;
            } else {
                _parameters.Add(param);
            }

            return new SimpleArgBuilder(info, info.ParameterType, index, param.IsParamsArray, param.IsParamsDict);
        }
开发者ID:BenHall,项目名称:ironruby,代码行数:10,代码来源:ParameterMapping.cs

示例15: SelectBestConversionFor

 /// <summary>
 /// Selects the best (of two) candidates for conversion from actualType
 /// </summary>
 public virtual Candidate SelectBestConversionFor(Type actualType, ParameterWrapper candidateOne, ParameterWrapper candidateTwo, NarrowingLevel level) {
     return Candidate.Equivalent;
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:6,代码来源:ActionBinder.cs


注:本文中的Microsoft.Scripting.Actions.Calls.ParameterWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。