public static Object FromJsValue(this JsValue val)
        {
            switch (val.Type)
            {
                case Types.Boolean:
                    return val.AsBoolean();
                case Types.Number:
                    return val.AsNumber();
                case Types.String:
                    return val.AsString();
                case Types.Object:
                    var obj = val.AsObject();
                    var node = obj as DomNodeInstance;

                    if (node != null)
                        return node.Value;

                    return obj;
                case Types.Undefined:
                    return "undefined";
                case Types.Null:
                    return null;
            }

            return val.ToObject();
        }
Beispiel #2
0
        public static object Uncast(this JsValue value)
        {
            if (value.IsBoolean()) {
                return value.AsBoolean();
            }
            if (value.IsNumber()) {
                return value.AsNumber();
            }
            if (value.IsObject()) {
                return value.AsObject();
            }
            if (value.IsString()) {
                return value.AsString();
            }

            return null;
        }
Beispiel #3
0
 public static string AsSqlBoolean(this object o)
 {
     return o.AsBoolean() ? "1" : "0";
 }
Beispiel #4
0
 public static string AsJSString(this object o)
 {
     if (o.AsBoolean())
     {
         return "true";
     }
     return "false";
 }
Beispiel #5
0
 /// <summary>
 /// Tries to get the result of calling <see cref="IValuedNode.AsBoolean()">AsBoolean()</see> on a node throwing an error if the node is null
 /// </summary>
 /// <param name="n">Node</param>
 /// <exception cref="RdfQueryException">Thrown if the input is null of the specific valued node cannot be cast to a boolean</exception>
 /// <returns></returns>
 public static bool AsSafeBoolean(this IValuedNode n)
 {
     if (n == null) throw new RdfQueryException("Cannot cast a null to a boolean");
     return n.AsBoolean();
 }
 public static bool AsBoolean(this object value)
 {
     return value.AsBoolean(false);
 }