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


C# PValue.TryConvertTo方法代码示例

本文整理汇总了C#中PValue.TryConvertTo方法的典型用法代码示例。如果您正苦于以下问题:C# PValue.TryConvertTo方法的具体用法?C# PValue.TryConvertTo怎么用?C# PValue.TryConvertTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PValue的用法示例。


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

示例1: _tryConvertToPair

 private static bool _tryConvertToPair(
     StackContext sctx, PValue inpv, out PValueKeyValuePair result)
 {
     PValue res;
     result = null;
     if (!inpv.TryConvertTo(sctx, typeof (PValueKeyValuePair), out res))
         return false;
     else
         result = (PValueKeyValuePair) res.Value;
     return true;
 }
开发者ID:SealedSun,项目名称:prx,代码行数:11,代码来源:HashPType.cs

示例2: _tryConvertToInt

        private static bool _tryConvertToInt(
            StackContext sctx, PValue operand, out int value, bool allowNull)
        {
            value = -1337; //should never surface as value is only used if the method returns true

            switch (operand.Type.ToBuiltIn())
            {
                case BuiltIn.Int:
                    value = Convert.ToInt32(operand.Value);
                    return true;
                    /*
                case BuiltIn.String:
                    string rawRight = operand.Value as string;
                    if (!int.TryParse(rawRight, out value))
                        value = 0;
                    return true; //*/
                case BuiltIn.Object:
                    PValue pvRight;
                    if (operand.TryConvertTo(sctx, Int, out pvRight))
                    {
                        value = (int) pvRight.Value;
                        return true;
                    }
                    break;
                case BuiltIn.Null:
                    value = 0;
                    return allowNull;
                default:
                    break;
            }

            return false;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:33,代码来源:IntPType.cs

示例3: _tryConvert

        private bool _tryConvert(StackContext sctx, PValue pv, out char c)
        {
            c = '\0';
            switch (pv.Type.ToBuiltIn())
            {
                case BuiltIn.Char:
                    c = (char) pv.Value;
                    return true;

                case BuiltIn.Int:
                    c = (char) (int) pv.Value;
                    return true;

                case BuiltIn.Null:
                    return true;

                case BuiltIn.String:
                    var s = (string) pv.Value;
                    if (s.Length == 1)
                    {
                        c = s[0];
                        return true;
                    }
                    else
                    {
                        return false;
                    }

                case BuiltIn.Object:
                    if (pv.TryConvertTo(sctx, Char, false, out pv))
                        return _tryConvert(sctx, pv, out c);
                    else
                        return false;

                case BuiltIn.Structure:
                case BuiltIn.Hash:
                case BuiltIn.List:
                case BuiltIn.Bool:
                case BuiltIn.None:
                case BuiltIn.Real:
                    return false;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:SealedSun,项目名称:prx,代码行数:46,代码来源:CharPType.cs

示例4: _ToEnumerable

        /// <summary>
        ///     Tries to turn a generic PValue object into an <see cref = "IEnumerable{PValue}" /> if possible. Returns null if <paramref
        ///      name = "psource" /> cannot be enumerated over.
        /// </summary>
        /// <param name = "sctx"></param>
        /// <param name = "psource"></param>
        /// <returns></returns>
        internal static IEnumerable<PValue> _ToEnumerable(StackContext sctx, PValue psource)
        {
            switch (psource.Type.ToBuiltIn())
            {
                case PType.BuiltIn.List:
                    return (IEnumerable<PValue>) psource.Value;
                case PType.BuiltIn.Object:
                    var clrType = ((ObjectPType) psource.Type).ClrType;
                    if (typeof (IEnumerable<PValue>).IsAssignableFrom(clrType))
                        goto case PType.BuiltIn.List;
                    else if (typeof (IEnumerable).IsAssignableFrom(clrType))
                        return _wrapNonGenericIEnumerable(sctx, (IEnumerable) psource.Value);

                    break;
            }
            IEnumerable<PValue> set;
            IEnumerable nset;
            if (psource.TryConvertTo(sctx, true, out set))
                return set;
            else if (psource.TryConvertTo(sctx, true, out nset))
                return _wrapNonGenericIEnumerable(sctx, nset);
            else
                return _wrapDynamicIEnumerable(sctx, psource);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:31,代码来源:Map.cs

示例5: _getMacroRef

 private static EntityRef _getMacroRef(StackContext sctx, PValue rawMacro)
 {
     PFunction func;
     MacroCommand mcmd;
     if (rawMacro.TryConvertTo(sctx, out func))
         return EntityRef.Function.Create(func.Id, func.ParentApplication.Module.Name);
     else if (rawMacro.TryConvertTo(sctx, out mcmd))
         return EntityRef.MacroCommand.Create(mcmd.Id);
     else
         return rawMacro.ConvertTo<EntityRef>(sctx);
 }
开发者ID:SealedSun,项目名称:prx,代码行数:11,代码来源:CallMacro.cs

示例6: _tryConvertToBool

        private static bool _tryConvertToBool(StackContext sctx, PValue operand, out bool value)
        {
            value = false;

            switch (operand.Type.ToBuiltIn())
            {
                case BuiltIn.Real:
                case BuiltIn.Int:
                case BuiltIn.Bool:
                    value = (bool) operand.Value;
                    return true;
                case BuiltIn.String:
                    if (!bool.TryParse(operand.Value as string, out value))
                    {
                        value = false;
                        return true;
                    }
                    break;
                case BuiltIn.Object:
                    PValue asBool;
                    if (operand.TryConvertTo(sctx, Bool, out asBool))
                    {
                        value = (bool) asBool.Value;
                        return true;
                    }
                    break;
                case BuiltIn.Null:
                    value = false;
                    return true;
            }

            return false;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:33,代码来源:BoolPType.cs

示例7: RunStatically

        public static PValue RunStatically(PValue arg0, PValue arg1, StackContext sctx)
        {
            var x = (double) arg0.ConvertTo(sctx, PType.Real, true).Value;

            int d;
            PValue pd;

            if (arg1 != null && arg1.TryConvertTo(sctx, PType.Int, true, out pd))
                d = System.Math.Abs((int) pd.Value);
            else
                d = 0;

            return System.Math.Round(x, d, MidpointRounding.AwayFromZero);
        }
开发者ID:SealedSun,项目名称:prx,代码行数:14,代码来源:Round.cs


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