Exemplo n.º 1
0
        private Object PerformWrite(Object value)
        {
            var str = Stringify.This(value);

            _interactivity.Write(str);
            return(null);
        }
Exemplo n.º 2
0
        private void Evaluate(String content, Boolean showOutput)
        {
            try
            {
                var result = _interactivity.Run(_engine, content);

                if (showOutput)
                {
                    var output = default(String);

                    if (result != null)
                    {
                        output = Stringify.This(result);
                    }

                    _interactivity.Info(output);
                    _engine.Scope["ans"] = result;
                }
            }
            catch (ParseException ex)
            {
                _interactivity.Display(ex.Error, content);
            }
            catch (Exception ex)
            {
                _interactivity.Error(ex.Message);
            }

            _interactivity.Write(Environment.NewLine);
        }
Exemplo n.º 3
0
        public void StringifyNullIsUndefined()
        {
            var value     = default(Object);
            var result    = Stringify.This(value);
            var undefined = Stringify.Undefined();

            Assert.AreEqual(undefined, result);
        }
Exemplo n.º 4
0
        private String Info(String topic, Object value)
        {
            var sb       = new StringBuilder();
            var type     = value.ToType();
            var typeName = $"{type["name"]}";

            sb.AppendFormat("Type of '{0}': ", topic);
            sb.AppendLine(typeName);
            sb.Append("Number value: ");
            sb.Append(Stringify.This(value.ToNumber()));
            sb.AppendLine();
            sb.Append("Boolean value: ");
            sb.Append(Stringify.This(value.ToBoolean()));
            sb.AppendLine();
            sb.Append("String value: ");
            sb.Append(Stringify.This(value));

            switch (typeName)
            {
            case "Number":
            case "Complex":
            case "String":
            case "Boolean":
            case "Function":
            case "Undefined":
                break;

            case "CMatrix":
                sb.AppendLine();
                sb.Append("Columns: ");
                sb.Append(((Complex[, ])value).GetLength(1));
                sb.AppendLine();
                sb.Append("Rows: ");
                sb.Append(((Complex[, ])value).GetLength(0));
                break;

            case "Matrix":
                sb.AppendLine();
                sb.Append("Columns: ");
                sb.Append(((Double[, ])value).GetLength(1));
                sb.AppendLine();
                sb.Append("Rows: ");
                sb.Append(((Double[, ])value).GetLength(0));
                break;

            case "Object":
                sb.AppendLine();
                sb.Append("Keys: ");
                sb.Append(String.Join(", ", ((IDictionary <String, Object>)value).Select(m => m.Key)));
                break;
            }

            return(sb.ToString());
        }
Exemplo n.º 5
0
        public void StringifyDelegateIsFunction()
        {
            var del   = new Function(args => null);
            var value = default(Object);

            value = del;
            var result = Stringify.This(value);
            var func   = Stringify.This(del);

            Assert.AreEqual(func, result);
        }
Exemplo n.º 6
0
        public void StringifyStringIsIdentity()
        {
            var str   = "Hallo";
            var value = default(Object);

            value = str;
            var result = Stringify.This(value);
            var self   = Stringify.This(str);

            Assert.AreEqual(self, result);
        }
Exemplo n.º 7
0
        public void StringifyBooleanIsBoolean()
        {
            var bln   = true;
            var value = default(Object);

            value = bln;
            var result  = Stringify.This(value);
            var boolean = Stringify.This(bln);

            Assert.AreEqual(boolean, result);
        }
Exemplo n.º 8
0
        public void StringifyDoubleIsNumber()
        {
            var dbl   = 2.0;
            var value = default(Object);

            value = dbl;
            var result = Stringify.This(value);
            var number = Stringify.This(dbl);

            Assert.AreEqual(number, result);
        }
Exemplo n.º 9
0
        public void StringifyDoubleUsesInvariantCulture()
        {
            var dbl     = 2.8;
            var thread  = Thread.CurrentThread;
            var culture = thread.CurrentUICulture;

            thread.CurrentCulture = new CultureInfo("de-de");
            Assert.AreEqual("2,8", dbl.ToString());
            Assert.AreEqual("2.8", Stringify.This(dbl));
            thread.CurrentCulture = culture;
        }
Exemplo n.º 10
0
        public void StringifyDictionaryIsObject()
        {
            var dict = new Dictionary <String, Object>
            {
                { "Foo", "Bar" }
            };
            var value = default(Object);

            value = dict;
            var result = Stringify.This(value);
            var obj    = Stringify.This(dict);

            Assert.AreEqual(obj, result);
        }
Exemplo n.º 11
0
 public void Info(Object result)
 {
     if (result == null)
     {
         Console.ForegroundColor = ConsoleColor.Yellow;
         Console.Write("Undefined");
         Console.ResetColor();
     }
     else
     {
         Console.ForegroundColor = ConsoleColor.White;
         Console.Write(Stringify.This(result));
         Console.ResetColor();
     }
 }
Exemplo n.º 12
0
        public void StringifyDoubleArrayIsMatrix()
        {
            var array = new Double[, ]
            {
                { 1, 2 },
                { 3, 4 }
            };
            var value = default(Object);

            value = array;
            var result = Stringify.This(value);
            var mat    = Stringify.This(array);

            Assert.AreEqual(mat, result);
        }
Exemplo n.º 13
0
        public static Object To(this Object value, String type)
        {
            switch (type)
            {
            case "Number": return(value.ToNumber());

            case "String": return(Stringify.This(value));

            case "Boolean": return(value.ToBoolean());

            case "Matrix": return(value.ToNumber().ToMatrix());

            case "Function": return(value as Function);

            case "Object": return(value as IDictionary <String, Object>);

            case "Undefined": return(null);
            }

            return(null);
        }
Exemplo n.º 14
0
        private String Info(String topic, Object value)
        {
            var sb = new StringBuilder();
            var type = value.ToType();
            sb.AppendFormat("Type of '{0}': ", topic);
            sb.AppendLine(type);
            sb.Append("Number value: ");
            sb.Append(Stringify.This(value.ToNumber()));
            sb.AppendLine();
            sb.Append("Boolean value: ");
            sb.Append(Stringify.This(value.ToBoolean()));
            sb.AppendLine();
            sb.Append("String value: ");
            sb.Append(Stringify.This(value));

            switch (type)
            {
                case "Number":
                    break;
                case "String":
                    break;
                case "Boolean":
                    break;
                case "Matrix":
                    break;
                case "Function":
                    break;
                case "Object":
                    sb.AppendLine();
                    sb.Append("Keys: ");
                    sb.Append(String.Join(", ", ((IDictionary<String, Object>)value).Select(m => m.Key)));
                    break;
                case "Undefined":
                    break;
            }

            return sb.ToString();
        }
Exemplo n.º 15
0
 void ITreeWalker.Visit(ConstantExpression expression)
 {
     Header("Expression/Constant/" + expression.Value.GetType().Name);
     WriteLine("- Value: " + Stringify.This(expression.Value));
 }
Exemplo n.º 16
0
        public void WriteLine(Object value)
        {
            var str = Stringify.This(value);

            Console.WriteLine(str);
        }