コード例 #1
0
ファイル: DebugViewGrid.cs プロジェクト: ngoffee/ela
        private string PrintValue(ElaValue value)
        {
            try
            {
                var result = String.Empty;
                var hdl    = new AutoResetEvent(false);
                var th     = new Thread(() =>
                {
                    var obj = value.AsObject();

                    if (obj is ElaLazy)
                    {
                        result = ((ElaLazy)obj).Force().AsObject().ToString();
                    }
                    else if (obj is ElaLazyList)
                    {
                        var lalist = (ElaLazyList)obj;
                        result     = ElaList.FromEnumerable(lalist.Take(20)).ToString() + " (lazy)";
                    }
                    else
                    {
                        result = value.ToString();
                    }

                    hdl.Set();
                });
                th.Start();

                if (!hdl.WaitOne(500))
                {
                    th.Abort();
                    result = "<evaluation timeout>";
                }

                if (result == null)
                {
                    return("_|_");
                }
                else if (result.Trim().Length == 0)
                {
                    result = "[" + value.GetTypeName() + "]";
                }

                return(result);
            }
            catch (Exception)
            {
                return("<evaluation error>");
            }
        }