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


C# PType.ToBuiltIn方法代码示例

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


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

示例1: InternalConvertTo

        protected override bool InternalConvertTo(
            StackContext sctx,
            PValue subject,
            PType target,
            bool useExplicit,
            out PValue result)
        {
            result = null;
            var s = (string) subject.Value;
            var builtInT = target.ToBuiltIn();
            if (useExplicit)
            {
                switch (builtInT)
                {
                    case BuiltIn.List:
                        var lst = _toPCharList(s);
                        result = (PValue) lst;
                        break;
                }
            }

            if (result == null)
            {
                switch (builtInT)
                {
                    case BuiltIn.Object:
                        var clrType = ((ObjectPType) target).ClrType;
                        var typeC = Type.GetTypeCode(clrType);
                        switch (typeC)
                        {
                            case TypeCode.String:
                                result = CreateObject(s);
                                break;
                            case TypeCode.Object:
                                if (clrType == typeof (IEnumerable<PValue>))
                                    result = (PValue) _toPCharList(s);
                                else if (clrType == typeof (char[]) ||
                                    clrType == typeof (IEnumerable<char>) ||
                                        clrType == typeof (ICollection<char>) ||
                                            clrType == typeof (IList<char>))
                                    result = new PValue(s.ToCharArray(), target);
                                break;
                        }
                        break;
                }
            }

            return result != null;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:49,代码来源:StringPType.cs

示例2: InternalConvertTo

        protected override bool InternalConvertTo(
            StackContext sctx,
            PValue subject,
            PType target,
            bool useExplicit,
            out PValue result)
        {
            result = null;
            switch (target.ToBuiltIn())
            {
                case BuiltIn.Real:
                    result = Real.CreatePValue(0.0);
                    break;
                case BuiltIn.Int:
                    result = Int.CreatePValue(0);
                    break;
                case BuiltIn.String:
                    result = String.CreatePValue("");
                    break;
                case BuiltIn.Bool:
                    result = Bool.CreatePValue(false);
                    break;
            }

            return result != null;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:26,代码来源:NullPType.cs

示例3: InternalConvertTo

        protected override bool InternalConvertTo(
            StackContext sctx, PValue subject, PType target, bool useExplicit, out PValue result)
        {
            if (sctx == null)
                throw new ArgumentNullException("sctx");
            if (subject == null || subject.IsNull)
                throw new ArgumentNullException("subject");
            if ((object) target == null)
                throw new ArgumentNullException("target");

            result = null;
            var c = (char) subject.Value;
            var bi = target.ToBuiltIn();

            if (useExplicit)
            {
                switch (bi)
                {
                    case BuiltIn.Object:
                        var clrType = ((ObjectPType) target).ClrType;
                        switch (Type.GetTypeCode(clrType))
                        {
                            case TypeCode.Byte:
                                result = new PValue(Convert.ToByte(c), target);
                                break;
                        }
                        break;
                }
            }

            if (result == null)
            {
                switch (bi)
                {
                    case BuiltIn.Int:
                        result = (int) c;
                        break;
                    case BuiltIn.String:
                        result = c.ToString();
                        break;
                    case BuiltIn.Object:
                        var clrType = ((ObjectPType) target).ClrType;
                        switch (Type.GetTypeCode(clrType))
                        {
                            case TypeCode.Char:
                                result = new PValue(c, target);
                                break;
                            case TypeCode.Int32:
                                result = new PValue((Int32) c, target);
                                break;
                        }
                        break;
                }
            }

            return result != null;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:57,代码来源:CharPType.cs

示例4: InternalConvertTo

        protected override bool InternalConvertTo(
            StackContext sctx,
            PValue subject,
            PType target,
            bool useExplicit,
            out PValue result)
        {
            result = null;
            var obj = subject.Value as SymbolTable<Member>;
            if (obj == null)
                return false;

            switch (target.ToBuiltIn())
            {
                case BuiltIn.String:
                    normalString:
                    if (
                        !TryDynamicCall(sctx, subject, new PValue[] {}, PCall.Get, "ToString",
                            out result))
                        result = null;
                    break;
                case BuiltIn.Object:
                    var clrType = ((ObjectPType) target).ClrType;
                    var tc = Type.GetTypeCode(clrType);
                    switch (tc)
                    {
                        case TypeCode.String:
                            goto normalString;
                    }
                    break;
            }

            return result != null;
        }
开发者ID:SealedSun,项目名称:prx,代码行数:34,代码来源:StructurePType.cs


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