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


C# ConversionResultKind类代码示例

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


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

示例1: Convert

 /// <summary>
 /// Backwards compatible Convert for the old sites that need to flow CodeContext
 /// </summary>
 public static Expression/*!*/ Convert(Expression/*!*/ codeContext, PythonContext/*!*/ binder, Type/*!*/ type, ConversionResultKind resultKind, Expression/*!*/ target) {
     return Ast.Dynamic(
         binder.Convert(type, resultKind),
         type,
         target
     );
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:10,代码来源:Binders.cs

示例2: ConvertExpression

        public override Ast ConvertExpression(Ast expr, Type toType, ConversionResultKind kind, OverloadResolverFactory resolverFactory)
        {
            Type exprType = expr.Type;
            Type visType = CompilerHelpers.GetVisibleType(toType);

            if (typeof(IFn).IsAssignableFrom(exprType) && typeof(Delegate).IsAssignableFrom(visType))
                return Ast.Call(typeof(Converter).GetMethod("ConvertToDelegate"), Ast.Convert(expr, typeof(IFn)), Expression.Constant(visType));

            // Follow through on our promise to convert IEnumerable<Object> or IEnumerable to IEnumerable<T> for any T
            if (toType.IsGenericType && ! toType.IsAssignableFrom(expr.Type))
            {
                // The following is inspired by IronPython.Runtime.Binding.Python.ConversionBinder.FallbackConvert
                Type genTo = toType.GetGenericTypeDefinition();
                if ( genTo == typeof(IList<>))
                {
                    return MakeToGenericConversion(expr,toType,typeof(IList<object>),typeof(ListGenericWrapper<>));
                }
                else if (genTo == typeof(IDictionary<,>))
                {
                    return MakeToGenericConversion(expr,toType,typeof(IDictionary<object,object>),typeof(DictionaryGenericWrapper<,>));
                }
                else if (genTo == typeof(IEnumerable<>))
                {   
                    return MakeToGenericConversion(expr, toType, typeof(IEnumerable),typeof(IEnumerableOfTWrapper<>));
                }
            }

            return base.ConvertExpression(expr, toType, kind, resolverFactory);
        }
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:29,代码来源:ClojureBinder.cs

示例3: ConversionBinder

        public ConversionBinder(BinderState/*!*/ state, Type/*!*/ type, ConversionResultKind resultKind)
            : base(type, resultKind == ConversionResultKind.ExplicitCast || resultKind == ConversionResultKind.ExplicitTry) {
            Assert.NotNull(state, type);

            _state = state;
            _kind = resultKind;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:7,代码来源:ConversionBinder.cs

示例4: ConvertExpression

        public override Expression ConvertExpression(Expression expr, Type toType, ConversionResultKind kind, OverloadResolverFactory resolverFactory)
        {
            ContractUtils.RequiresNotNull(expr, "expr");
            ContractUtils.RequiresNotNull(toType, "toType");

            Type exprType = expr.Type;

            if (toType == typeof(object))
            {
                if (exprType.IsValueType())
                    return Utils.Convert(expr, toType);
                else
                    return expr;
            }

            if (toType.IsAssignableFrom(exprType))
                return expr;

            Type visType = Context.Binder.PrivateBinding ? toType : CompilerHelpers.GetVisibleType(toType);

            return Binders.Convert(
                _context,
                visType,
                kind,
                expr
            );
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:27,代码来源:TotemBinder.cs

示例5: ConvertTo

        public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, DynamicMetaObject arg, OverloadResolverFactory resolverFactory, DynamicMetaObject errorSuggestion) {
            ContractUtils.RequiresNotNull(toType, "toType");
            ContractUtils.RequiresNotNull(arg, "arg");

            Type knownType = arg.GetLimitType();

            // try all the conversions - first look for conversions against the expression type,
            // these can be done w/o any additional tests.  Then look for conversions against the 
            // restricted type.
            BindingRestrictions typeRestrictions = arg.Restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(arg.Expression, arg.GetLimitType()));

            DynamicMetaObject res = 
                TryConvertToObject(toType, arg.Expression.Type, arg, typeRestrictions) ??
                TryAllConversions(resolverFactory, toType, kind, arg.Expression.Type, typeRestrictions, arg) ??
                TryAllConversions(resolverFactory, toType, kind, arg.GetLimitType(), typeRestrictions, arg) ??
                errorSuggestion ??
                MakeErrorTarget(toType, kind, typeRestrictions, arg);

            if ((kind == ConversionResultKind.ExplicitTry || kind == ConversionResultKind.ImplicitTry) && toType.IsValueType) {
                res = new DynamicMetaObject(
                    AstUtils.Convert(
                        res.Expression,
                        typeof(object)
                    ),
                    res.Restrictions
                );
            }
            return res;
        }
开发者ID:BenHall,项目名称:ironruby,代码行数:29,代码来源:DefaultBinder.Conversions.cs

示例6: ConvertWorker

        public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type toType, ConversionResultKind kind) {
            if (toType.IsSubclassOf(typeof(Delegate))) {
                return MakeDelegateTarget(binder, toType, Restrict(typeof(Method)));
            }

            return FallbackConvert(binder);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:7,代码来源:MetaMethod.cs

示例7: ConvertExpression

        public override Expression/*!*/ ConvertExpression(Expression/*!*/ expr, Type/*!*/ toType, ConversionResultKind kind, Expression context) {
            ContractUtils.RequiresNotNull(expr, "expr");
            ContractUtils.RequiresNotNull(toType, "toType");

            Type exprType = expr.Type;

            if (toType == typeof(object)) {
                if (exprType.IsValueType) {
                    return AstUtils.Convert(expr, toType);
                } else {
                    return expr;
                }
            }

            if (toType.IsAssignableFrom(exprType)) {
                return expr;
            }

            Type visType = CompilerHelpers.GetVisibleType(toType);

            if (exprType == typeof(PythonType) && visType == typeof(Type)) {
                return AstUtils.Convert(expr, visType); // use the implicit conversion
            }

            return Binders.Convert(
                context,
                _context.DefaultBinderState,
                visType,
                visType == typeof(char) ? ConversionResultKind.ImplicitCast : kind,
                expr
            );
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:32,代码来源:PythonBinder.cs

示例8: Convert

 public static Expression Convert(TotemContext state, Type type, ConversionResultKind kind, Expression target)
 {
     return DynamicExpression.Dynamic(
         state.Convert(type, kind),
         type,
         target
     );
 }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:8,代码来源:Binders.cs

示例9: TryAllConversions

 /// <summary>
 /// Checks if any conversions are available and if so builds the target for that conversion.
 /// </summary>
 private DynamicMetaObject TryAllConversions(Type toType, ConversionResultKind kind, Type knownType, BindingRestrictions restrictions, DynamicMetaObject arg) {
     return
         TryAssignableConversion(toType, knownType, restrictions, arg) ??           // known type -> known type
         TryExtensibleConversion(toType, knownType, restrictions, arg) ??           // Extensible<T> -> Extensible<T>.Value
         TryUserDefinedConversion(kind, toType, knownType, restrictions, arg) ??    // op_Implicit
         TryImplicitNumericConversion(toType, knownType, restrictions, arg) ??      // op_Implicit
         TryNullableConversion(toType, kind, knownType, restrictions, arg) ??       // null -> Nullable<T> or T -> Nullable<T>
         TryNullConversion(toType, knownType, restrictions);                        // null -> reference type
 }
开发者ID:Hank923,项目名称:ironruby,代码行数:12,代码来源:DefaultBinder.Conversions.cs

示例10: TotemConversionBinder

        public TotemConversionBinder(TotemContext/*!*/ context, Type/*!*/ type, ConversionResultKind resultKind, bool retObj)
            : base(retObj ? typeof(object) : type, resultKind == ConversionResultKind.ExplicitCast || resultKind == ConversionResultKind.ExplicitTry)
        {
            Assert.NotNull(context);

            _context = context;
            _kind = resultKind;
            _retObject = retObj;
            _type = type;
        }
开发者ID:Alxandr,项目名称:IronTotem,代码行数:10,代码来源:TotemConversionBinder.cs

示例11: ConvertExpression

        public override Ast ConvertExpression(Ast expr, Type toType, ConversionResultKind kind, OverloadResolverFactory resolverFactory)
        {
            Type exprType = expr.Type;
            Type visType = CompilerHelpers.GetVisibleType(toType);

            if (typeof(IFn).IsAssignableFrom(exprType) && typeof(Delegate).IsAssignableFrom(visType))
                return Ast.Call(typeof(Converter).GetMethod("ConvertToDelegate"), Ast.Convert(expr, typeof(IFn)), Expression.Constant(visType));

            return base.ConvertExpression(expr, toType, kind, resolverFactory);
        }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:10,代码来源:ClojureBinder.cs

示例12: ConvertWorker

        public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type toType, ConversionResultKind kind) {
            PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "BuiltinFunc Convert " + toType);
            PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "BuiltinFunc Convert");

            if (toType.IsSubclassOf(typeof(Delegate))) {
                return MakeDelegateTarget(binder, toType, Restrict(LimitType));
            }

            return FallbackConvert(binder);
        }
开发者ID:rafacv,项目名称:iron_languages,代码行数:10,代码来源:MetaBuiltinFunction.cs

示例13: Convert

 /// <summary>
 /// Backwards compatible Convert for the old sites that need to flow CodeContext
 /// </summary>
 public static Expression/*!*/ Convert(Expression/*!*/ codeContext, BinderState/*!*/ binder, Type/*!*/ type, ConversionResultKind resultKind, Expression/*!*/ target) {
     return Ast.Dynamic(
         new ConversionBinder(
             binder,
             type,
             resultKind
         ),
         type,
         target
     );
 }
开发者ID:octavioh,项目名称:ironruby,代码行数:14,代码来源:Binders.cs

示例14: ConvertWorker

        public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type, Type retType, ConversionResultKind kind) {
            PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Conversion " + type.FullName);
            PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "Conversion");
            ValidationInfo typeTest = BindingHelpers.GetValidationInfo(this, Value.PythonType);

            return BindingHelpers.AddDynamicTestAndDefer(
                binder,
                TryPythonConversion(binder, type) ?? FallbackConvert(binder),
                new DynamicMetaObject[] { this },
                typeTest,
                retType
            );
        }
开发者ID:jschementi,项目名称:iron,代码行数:13,代码来源:MetaUserObject.cs

示例15: ConvertTo

        public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, DynamicMetaObject arg) {
            ContractUtils.RequiresNotNull(toType, "toType");
            ContractUtils.RequiresNotNull(arg, "arg");

            Type knownType = arg.GetLimitType();

            // try all the conversions - first look for conversions against the expression type,
            // these can be done w/o any additional tests.  Then look for conversions against the 
            // restricted type.
            BindingRestrictions typeRestrictions = arg.Restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(arg.Expression, arg.GetLimitType()));

            return
                TryConvertToObject(toType, arg.Expression.Type, arg) ??
                TryAllConversions(toType, kind, arg.Expression.Type, arg.Restrictions, arg) ??
                TryAllConversions(toType, kind, arg.GetLimitType(), typeRestrictions, arg) ??
                MakeErrorTarget(toType, kind, typeRestrictions, arg);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:17,代码来源:DefaultBinder.Conversions.cs


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