static string?AsString(JsValue?value, JsonInstance json, bool formatForRaw)
 {
     return(value switch {
         JsBoolean b => b.AsBoolean() ? "true" : "false",
         JsString s => formatForRaw ? $"\"{s.AsString()}\"": s.AsString(),
         JsNumber n => n.AsNumber().ToString(CultureInfo.InvariantCulture),
         JsNull => null,
         JsUndefined => null,
         { } v => json.Stringify(JsValue.Undefined, new[] { v }).AsString(),
         _ => null
     });
Example #2
0
 string?AsString(JsValue?value)
 {
     return(value switch {
         JsBoolean b => b.AsBoolean() ? "true" : "false",
         JsString s => s.AsString(),
         JsNumber n => n.AsNumber().ToString(CultureInfo.InvariantCulture),
         JsNull => null,
         JsUndefined => null,
         { } v => _json.Stringify(JsValue.Undefined, new[] { v }).AsString(),
         _ => null
     });
        public void ShouldBeAString()
        {
            var value = new JsString("a");

            Assert.Equal(false, value.IsBoolean());
            Assert.Equal(false, value.IsArray());
            Assert.Equal(false, value.IsDate());
            Assert.Equal(false, value.IsNull());
            Assert.Equal(false, value.IsNumber());
            Assert.Equal(false, value.IsObject());
            Assert.Equal(true, value.IsPrimitive());
            Assert.Equal(false, value.IsRegExp());
            Assert.Equal(true, value.IsString());
            Assert.Equal("a", value.AsString());
            Assert.Equal(false, value.IsUndefined());
        }