本文整理汇总了C#中JSObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# JSObject.GetType方法的具体用法?C# JSObject.GetType怎么用?C# JSObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSObject
的用法示例。
在下文中一共展示了JSObject.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: valueOf
public static JSObject valueOf(JSObject self)
{
if (self.GetType() == typeof(Number))
return self.iValue == 0 ? self.dValue : self.iValue;
if (self.valueType != JSObjectType.Int && self.valueType != JSObjectType.Double)
throw new JSException((new TypeError("Try to call Number.valueOf on not number object.")));
return self;
}
示例2: toString
public static JSObject toString(JSObject self, Arguments radix)
{
var ovt = self.valueType;
if (self.valueType > JSObjectType.Double && self.GetType() == typeof(Number))
self.valueType = self.dValue == 0.0 ? JSObjectType.Int : JSObjectType.Double;
try
{
if (self.valueType != JSObjectType.Int && self.valueType != JSObjectType.Double)
throw new JSException((new TypeError("Try to call Number.toString on not Number object")));
int r = 10;
if (radix != null && radix.GetMember("length").iValue > 0)
{
var ar = radix[0];
if (ar.valueType == JSObjectType.Object && ar.oValue == null)
throw new JSException((new Error("Radix can't be null.")));
switch (ar.valueType)
{
case JSObjectType.Int:
case JSObjectType.Bool:
{
r = ar.iValue;
break;
}
case JSObjectType.Double:
{
r = (int)ar.dValue;
break;
}
case JSObjectType.NotExistsInObject:
case JSObjectType.Undefined:
{
r = 10;
break;
}
default:
{
r = Tools.JSObjectToInt32(ar);
break;
}
}
}
if (r < 2 || r > 36)
throw new JSException((new TypeError("Radix must be between 2 and 36.")));
if (r == 10)
return self.ToString();
else
{
long res = self.iValue;
var sres = new StringBuilder();
bool neg;
if (self.valueType == JSObjectType.Double)
{
if (double.IsNaN(self.dValue))
return "NaN";
if (double.IsPositiveInfinity(self.dValue))
return "Infinity";
if (double.IsNegativeInfinity(self.dValue))
return "-Infinity";
res = (long)self.dValue;
if (res != self.dValue) // your bunny wrote
{
double dtemp = self.dValue;
neg = dtemp < 0;
if (neg)
dtemp = -dtemp;
sres.Append(Tools.NumChars[(int)(dtemp % r)]);
res /= r;
while (dtemp >= 1.0)
{
sres.Append(Tools.NumChars[(int)(dtemp % r)]);
dtemp /= r;
}
if (neg)
sres.Append('-');
for (int i = sres.Length - 1, j = 0; i > j; j++, i--)
{
sres[i] ^= sres[j];
sres[j] ^= sres[i];
sres[i] ^= sres[j];
sres[i] += (char)((sres[i] / 'A') * ('a' - 'A'));
sres[j] += (char)((sres[j] / 'A') * ('a' - 'A'));
}
return sres.ToString();
}
}
neg = res < 0;
if (neg)
res = -res;
if (res < 0)
throw new JSException(new Error("Internal error"));
sres.Append(Tools.NumChars[res % r]);
res /= r;
while (res != 0)
{
sres.Append(Tools.NumChars[res % r]);
res /= r;
}
if (neg)
sres.Append('-');
for (int i = sres.Length - 1, j = 0; i > j; j++, i--)
//.........这里部分代码省略.........
示例3: toFixed
public static JSObject toFixed(JSObject self, Arguments digits)
{
double res = 0;
switch (self.valueType)
{
case JSObjectType.Int:
{
res = self.iValue;
break;
}
case JSObjectType.Double:
{
res = self.dValue;
break;
}
case JSObjectType.Object:
{
if (typeof(Number) != self.GetType())
throw new JSException((new TypeError("Try to call Number.toFixed on not number object.")));
res = self.iValue == 0 ? self.dValue : self.iValue;
break;
}
default:
throw new InvalidOperationException();
}
int dgts = Tools.JSObjectToInt32(digits[0], true);
if (dgts < 0 || dgts > 20)
throw new JSException((new RangeError("toFixed() digits argument must be between 0 and 20")));
if (System.Math.Abs(self.dValue) >= 1e+21)
return self.dValue.ToString("0.####e+0", System.Globalization.CultureInfo.InvariantCulture);
if (dgts > 0)
dgts++;
return System.Math.Round(res, dgts).ToString("0.00000000000000000000".Substring(0, dgts + 1), System.Globalization.CultureInfo.InvariantCulture);
}
示例4: toExponential
public static JSObject toExponential(JSObject self, Arguments digits)
{
double res = 0;
switch (self.valueType)
{
case JSObjectType.Int:
{
res = self.iValue;
break;
}
case JSObjectType.Double:
{
res = self.dValue;
break;
}
case JSObjectType.Object:
{
if (typeof(Number) != self.GetType())
throw new JSException((new TypeError("Try to call Number.toExponential on not number object.")));
res = self.iValue == 0 ? self.dValue : self.iValue;
break;
}
default:
throw new InvalidOperationException();
}
int dgts = 0;
switch ((digits ?? JSObject.undefined).valueType)
{
case JSObjectType.Int:
{
dgts = digits.iValue;
break;
}
case JSObjectType.Double:
{
dgts = (int)digits.dValue;
break;
}
case JSObjectType.String:
{
double d = 0;
int i = 0;
if (Tools.ParseNumber(digits.oValue.ToString(), i, out d, Tools.ParseNumberOptions.Default))
dgts = (int)d;
break;
}
case JSObjectType.Object:
{
var d = digits[0].ToPrimitiveValue_Value_String();
if (d.valueType == JSObjectType.String)
goto case JSObjectType.String;
if (d.valueType == JSObjectType.Int)
goto case JSObjectType.Int;
if (d.valueType == JSObjectType.Double)
goto case JSObjectType.Double;
break;
}
default:
return res.ToString("e", System.Globalization.CultureInfo.InvariantCulture);
}
return res.ToString("e" + dgts, System.Globalization.CultureInfo.InvariantCulture);
}
示例5: toString
public static JSObject toString(JSObject self, Arguments args)
{
if (self.GetType() != typeof(Boolean) && self.valueType != JSObjectType.Bool)
throw new JSException(new TypeError("Boolean.prototype.toString called for not boolean."));
return self.iValue != 0 ? "true" : "false";
}
示例6: valueOf
public static JSObject valueOf(JSObject self)
{
if (self.GetType() == typeof(Boolean))
return self.iValue != 0;
if (!typeof(JSObject).IsAssignableFrom(self.GetType()) || self.valueType != JSObjectType.Bool)
throw new JSException(new TypeError("Boolean.prototype.valueOf called for not boolean."));
return self;
}