本文整理汇总了C#中Jint.Native.JsValue.IsUndefined方法的典型用法代码示例。如果您正苦于以下问题:C# JsValue.IsUndefined方法的具体用法?C# JsValue.IsUndefined怎么用?C# JsValue.IsUndefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jint.Native.JsValue
的用法示例。
在下文中一共展示了JsValue.IsUndefined方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBeADate
public void ShouldBeADate()
{
var value = new JsValue(new DateInstance(null));
Assert.Equal(false, value.IsBoolean());
Assert.Equal(false, value.IsArray());
Assert.Equal(true, value.IsDate());
Assert.Equal(false, value.IsNull());
Assert.Equal(false, value.IsNumber());
Assert.Equal(true, value.IsObject());
Assert.Equal(false, value.IsPrimitive());
Assert.Equal(false, value.IsRegExp());
Assert.Equal(false, value.IsString());
Assert.Equal(false, value.IsUndefined());
Assert.Equal(true, value.AsDate() != null);
}
示例2: ToRavenJToken
private RavenJToken ToRavenJToken(JsValue v, string propertyKey)
{
if (v.IsBoolean())
return new RavenJValue(v.AsBoolean());
if (v.IsString())
{
const string RavenDataByteArrayToBase64 = "raven-data:byte[];base64,";
var value = v.AsString();
if (value != null && value.StartsWith(RavenDataByteArrayToBase64))
{
value = value.Remove(0, RavenDataByteArrayToBase64.Length);
var byteArray = Convert.FromBase64String(value);
return new RavenJValue(byteArray);
}
return new RavenJValue(value);
}
if (v.IsNumber())
{
var num = v.AsNumber();
KeyValuePair<RavenJValue, JsValue> property;
if (propertiesByValue.TryGetValue(propertyKey, out property))
{
var originalValue = property.Key;
if (originalValue.Type == JTokenType.Float)
return new RavenJValue(num);
if (originalValue.Type == JTokenType.Integer)
{
// If the current value is exactly as the original value, we can return the original value before we made the JS conversion,
// which will convert a Int64 to jsFloat.
var originalJsValue = property.Value;
if (originalJsValue.IsNumber() && Math.Abs(num - originalJsValue.AsNumber()) < double.Epsilon)
return originalValue;
return new RavenJValue((long)num);
}
}
// If we don't have the type, assume that if the number ending with ".0" it actually an integer.
var integer = Math.Truncate(num);
if (Math.Abs(num - integer) < double.Epsilon)
return new RavenJValue((long)integer);
return new RavenJValue(num);
}
if (v.IsNull())
return RavenJValue.Null;
if (v.IsUndefined())
return RavenJValue.Null;
if (v.IsArray())
{
var jsArray = v.AsArray();
var rja = new RavenJArray();
foreach (var property in jsArray.Properties)
{
if (property.Key == "length")
continue;
var jsInstance = property.Value.Value;
if (!jsInstance.HasValue)
continue;
var ravenJToken = ToRavenJToken(jsInstance.Value, CreatePropertyKey(property.Key, propertyKey));
if (ravenJToken == null)
continue;
rja.Add(ravenJToken);
}
return rja;
}
if (v.IsObject())
return ToRavenJObject(v, propertyKey);
if (v.IsRegExp())
return null;
throw new NotSupportedException(v.Type.ToString());
}
示例3: ToRavenJToken
private RavenJToken ToRavenJToken(JsValue v, string propertyKey, bool recursiveCall)
{
if (v.IsBoolean())
return new RavenJValue(v.AsBoolean());
if (v.IsString())
{
const string RavenDataByteArrayToBase64 = "raven-data:byte[];base64,";
var valueAsObject = v.ToObject();
var value = valueAsObject != null ? valueAsObject.ToString() : null;
if (value != null && value.StartsWith(RavenDataByteArrayToBase64))
{
value = value.Remove(0, RavenDataByteArrayToBase64.Length);
var byteArray = Convert.FromBase64String(value);
return new RavenJValue(byteArray);
}
return new RavenJValue(value);
}
if (v.IsNumber())
{
var num = v.AsNumber();
KeyValuePair<RavenJValue, JsValue> property;
if (propertiesByValue.TryGetValue(propertyKey, out property))
{
var originalValue = property.Key;
if (originalValue.Type == JTokenType.Float ||
originalValue.Type == JTokenType.Integer)
{
// If the current value is exactly as the original value, we can return the original value before we made the JS conversion,
// which will convert a Int64 to jsFloat.
var originalJsValue = property.Value;
if (originalJsValue.IsNumber() && Math.Abs(num - originalJsValue.AsNumber()) < double.Epsilon)
return originalValue;
//We might have change the type of num from Integer to long in the script by design
//Making sure the number isn't a real float before returning it as integer
if (originalValue.Type == JTokenType.Integer && (Math.Abs(num - Math.Floor(num)) <= double.Epsilon || Math.Abs(num - Math.Ceiling(num)) <= double.Epsilon))
return new RavenJValue((long)num);
return new RavenJValue(num);//float
}
}
// If we don't have the type, assume that if the number ending with ".0" it actually an integer.
var integer = Math.Truncate(num);
if (Math.Abs(num - integer) < double.Epsilon)
return new RavenJValue((long)integer);
return new RavenJValue(num);
}
if (v.IsNull())
return RavenJValue.Null;
if (v.IsUndefined())
return RavenJValue.Null;
if (v.IsArray())
{
var jsArray = v.AsArray();
var rja = new RavenJArray();
foreach (var property in jsArray.Properties)
{
if (InheritedProperties.Contains(property.Key))
continue;
var jsInstance = property.Value.Value;
if (!jsInstance.HasValue)
continue;
var ravenJToken = ToRavenJToken(jsInstance.Value, propertyKey + "["+property.Key +"]", recursiveCall);
if (ravenJToken == null)
continue;
rja.Add(ravenJToken);
}
return rja;
}
if (v.IsObject())
{
return ToRavenJObject(v, propertyKey, recursiveCall);
}
if (v.IsRegExp())
return null;
throw new NotSupportedException(v.Type.ToString());
}