Exemplo n.º 1
0
 public static void Setter(this IDictionary <String, Object> obj, Object[] arguments, Object value)
 {
     if (arguments.Length > 0)
     {
         var name = Stringify.This(arguments[0]);
         obj.SetProperty(name, value);
     }
 }
Exemplo n.º 2
0
 public static Object Add(Object[] args)
 {
     return(Curry.MinTwo(StandardOperators.Add, args) ??
            If.Is <Double, Double>(args, (y, x) => x + y) ??
            If.Is <Double[, ], Double[, ]>(args, (y, x) => x.Add(y)) ??
            If.Is <String, String>(args, (y, x) => String.Concat(x, y)) ??
            If.Is <Object, String>(args, (y, x) => String.Concat(x, Stringify.This(y))) ??
            If.Is <String, Object>(args, (y, x) => String.Concat(Stringify.This(x), y)));
 }
Exemplo n.º 3
0
        public static Object Getter(this IDictionary <String, Object> obj, Object[] arguments)
        {
            if (arguments.Length > 0)
            {
                var name = Stringify.This(arguments[0]);
                return(obj.GetProperty(name));
            }

            return(null);
        }
Exemplo n.º 4
0
 private void SerializeTo(Object value, StringBuilder buffer, Int32 level)
 {
     if (value == null)
     {
         buffer.Append("null");
     }
     else if (value is Function)
     {
         buffer.Append(Stringify.AsJson("[Function]"));
     }
     else if (value is IDictionary <String, Object> o)
     {
         if (!_seen.Contains(value.Unwrap()))
         {
             SerializeTo(o, buffer, level);
         }
         else
         {
             buffer.Append(Stringify.AsJson("[Recursion]"));
         }
     }
     else if (value is Double[,] m)
     {
         buffer.Append(Stringify.AsJson(m));
     }
     else if (value is String s)
     {
         buffer.Append(Stringify.AsJson(s));
     }
     else if (value is Double d)
     {
         buffer.Append(Stringify.This(d));
     }
     else if (value is Boolean b)
     {
         buffer.Append(Stringify.This(b));
     }
     else if (value is Complex c)
     {
         SerializeTo(new Dictionary <String, Object>
         {
             { "type", "cmplx" },
             { "real", c.Real },
             { "imag", c.Imaginary },
         }, buffer, level);
     }
     else
     {
         buffer.Append("undefined");
     }
 }
Exemplo n.º 5
0
 public static Object Eq(Object[] args)
 {
     return(Curry.MinTwo(StandardOperators.Eq, args) ??
            If.Is <Double, Double>(args, (y, x) => x == y) ??
            If.Is <Boolean, Boolean>(args, (y, x) => x == y) ??
            If.Is <Double[, ], Double[, ]>(args, (y, x) => x.AreEqual(y)) ??
            If.Is <Double[, ], Double>(args, (y, x) => y.AreEqual(x)) ??
            If.Is <Double, Double[, ]>(args, (y, x) => x.AreEqual(y)) ??
            If.Is <Double[, ], Boolean>(args, (y, x) => y.AreEqual(x.ToNumber())) ??
            If.Is <Boolean, Double[, ]>(args, (y, x) => x.AreEqual(y.ToNumber())) ??
            If.Is <String, String>(args, (y, x) => y.Equals(x)) ??
            If.Is <String, Object>(args, (y, x) => y.Equals(Stringify.This(x))) ??
            If.Is <Object, String>(args, (y, x) => x.Equals(Stringify.This(y))) ??
            Object.ReferenceEquals(args[1], args[0]));
 }
Exemplo n.º 6
0
 private void SerializeTo(Object value, StringBuilder buffer, Int32 level)
 {
     if (value == null)
     {
         buffer.Append("null");
     }
     else if (value is Function)
     {
         buffer.Append(Stringify.AsJson("[Function]"));
     }
     else if (value is IDictionary <String, Object> )
     {
         if (!_seen.Contains(value.Unwrap()))
         {
             SerializeTo((IDictionary <String, Object>)value, buffer, level);
         }
         else
         {
             buffer.Append(Stringify.AsJson("[Recursion]"));
         }
     }
     else if (value is Double[, ])
     {
         buffer.Append(Stringify.AsJson((Double[, ])value));
     }
     else if (value is String)
     {
         buffer.Append(Stringify.AsJson((String)value));
     }
     else if (value is Double)
     {
         buffer.Append(Stringify.This((Double)value));
     }
     else if (value is Boolean)
     {
         buffer.Append(Stringify.This((Boolean)value));
     }
     else
     {
         buffer.Append("undefined");
     }
 }