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
     });
예제 #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
     });
예제 #3
0
        public void ShouldBeANumber()
        {
            var value = new JsNumber(2);

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