本文整理汇总了C#中JSObject.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JSObject.ToString方法的具体用法?C# JSObject.ToString怎么用?C# JSObject.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSObject
的用法示例。
在下文中一共展示了JSObject.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BestMessage
private static string BestMessage(JSObject obj)
{
var err = obj as JSError;
if (err != null)
return err.Message;
else
return obj.ToString();
}
示例2: charAt
public static String charAt(JSObject self, Arguments pos)
{
var strValue = self.ToString();
int p = Tools.JSObjectToInt32(pos[0], true);
if ((p < 0) || (p >= strValue.Length))
return "";
return strValue[p].ToString();//Tools.charStrings[strValue[p]];
}
示例3: GetMember
internal protected override JS.Core.JSObject GetMember(JSObject nameObj, bool create, bool own)
{
var name = nameObj.ToString();
JS.Core.JSObject res = null;
if (childs.TryGetValue(name, out res))
return res;
string reqname = Namespace + "." + name;
var selection = types.StartedWith(reqname).GetEnumerator();
if (selection.MoveNext())
{
if (unions != null && selection.Current.Key != reqname && selection.Current.Value.FullName[reqname.Length] == '`')
{
var ut = new GenericType(reqname);
ut.Add(selection.Current.Value);
while (selection.MoveNext())
if (selection.Current.Value.FullName[reqname.Length] == '`')
{
string fn = selection.Current.Value.FullName;
for (var i = fn.Length - 1; i > reqname.Length; i--)
if (!char.IsDigit(fn[i]))
{
fn = null;
break;
}
if (fn != null)
ut.Add(selection.Current.Value);
}
res = TypeProxy.GetConstructor(ut);
childs[name] = res;
return res;
}
if (selection.Current.Key == reqname)
return TypeProxy.GetConstructor(selection.Current.Value);
res = TypeProxy.Proxy(new NamespaceProvider(reqname, unions != null));
childs.Add(name, res);
return res;
}
return new JS.Core.JSObject();
}
示例4: substr
public static JSObject substr(JSObject self, Arguments args)
{
if (args.Length == 0)
return self;
int pos0 = 0;
if (args.Length > 0)
{
switch (args[0].valueType)
{
case JSObjectType.Int:
case JSObjectType.Bool:
{
pos0 = args[0].iValue;
break;
}
case JSObjectType.Double:
{
pos0 = (int)args[0].dValue;
break;
}
case JSObjectType.Object:
case JSObjectType.Date:
case JSObjectType.Function:
case JSObjectType.String:
{
double d;
Tools.ParseNumber(args[0].ToString(), pos0, out d, Tools.ParseNumberOptions.Default);
pos0 = (int)d;
break;
}
}
}
var selfs = self.ToString();
int len = selfs.Length - pos0;
if (args.Length > 1)
{
switch (args[1].valueType)
{
case JSObjectType.Int:
case JSObjectType.Bool:
{
len = args[1].iValue;
break;
}
case JSObjectType.Double:
{
len = (int)args[1].dValue;
break;
}
case JSObjectType.Object:
case JSObjectType.Date:
case JSObjectType.Function:
case JSObjectType.String:
{
double d;
Tools.ParseNumber(args[1].ToString(), len, out d, Tools.ParseNumberOptions.Default);
len = (int)d;
break;
}
}
}
if (pos0 < 0)
pos0 += selfs.Length;
if (pos0 < 0)
pos0 = 0;
if (pos0 >= selfs.Length || len <= 0)
return "";
if (selfs.Length < pos0 + len)
len = selfs.Length - pos0;
return selfs.Substring(pos0, len);
}
示例5: stringifyImpl
private static string stringifyImpl(string key, JSObject obj, Function replacer, string space, List<JSObject> processed, Arguments args)
{
if (processed.IndexOf(obj) != -1)
throw new JSException(new TypeError("Can not convert circular structure to JSON."));
processed.Add(obj);
try
{
{
if (replacer != null)
{
args[0] = "";
args[0].oValue = key;
args[1] = obj;
args.length = 2;
var t = replacer.Invoke(args);
if (t.valueType <= JSObjectType.Undefined || (t.valueType >= JSObjectType.Object && t.oValue == null))
return null;
obj = t;
}
}
if (obj.valueType <= JSObjectType.Undefined
|| obj.valueType == JSObjectType.Function)
return null;
obj = obj.Value as JSObject ?? obj;
StringBuilder res = null;
string strval = null;
if (obj.valueType < JSObjectType.Object)
{
if (obj.valueType == JSObjectType.String)
{
res = new StringBuilder("\"");
strval = obj.ToString();
for (var i = 0; i < strval.Length ; i++)
escapeIfNeed(res, strval[i]);
res.Append('"');
return res.ToString();
}
return obj.ToString();
}
if (obj.Value == null)
return "null";
var toJSONmemb = obj["toJSON"];
toJSONmemb = toJSONmemb.Value as JSObject ?? toJSONmemb;
if (toJSONmemb.valueType == JSObjectType.Function)
return stringifyImpl("", (toJSONmemb.oValue as Function).Invoke(obj, null), null, space, processed, null);
res = new StringBuilder(obj is Array ? "[" : "{");
bool first = true;
foreach (var member in obj)
{
var value = obj[member];
value = value.Value as JSObject ?? value;
if (value.valueType < JSObjectType.Undefined)
continue;
if (value.valueType == JSObjectType.Property)
value = ((value.oValue as PropertyPair).get ?? Function.emptyFunction).Invoke(obj, null);
strval = stringifyImpl(member, value, replacer, space, processed, args);
if (strval == null)
continue;
if (!first)
res.Append(",");
if (space != null)
res.Append(Environment.NewLine);
if (space != null)
res.Append(space);
if (res[0] == '[')
{
if (space != null)
res.Append(space);
/*
for (var i = 0; i < strval.Length; i++)
{
escapeIfNeed(res, strval[i]);
}
*/
res.Append(strval);
}
else
{
res.Append('"');
for (var i = 0; i < member.Length; i++)
{
escapeIfNeed(res, member[i]);
}
res.Append("\":")
.Append(space ?? "");
/*
if (strval.Length > 0 && strval[0] == '"')
{
res.Append(strval[0]);
for (var i = 1; i < strval.Length - 1; i++)
{
escapeIfNeed(res, strval[i]);
}
if (strval.Length > 1)
res.Append(strval[strval.Length - 1]);
}
else
*/
{
for (var i = 0; i < strval.Length; i++)
//.........这里部分代码省略.........
示例6: 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--)
//.........这里部分代码省略.........
示例7: GetMember
internal protected override JSObject GetMember(JSObject name, bool forWrite, bool own)
{
int index = 0;
double dindex = Tools.JSObjectToDouble(name);
if (!double.IsInfinity(dindex)
&& !double.IsNaN(dindex)
&& ((index = (int)dindex) == dindex)
&& ((index = (int)dindex) == dindex)
&& index < (oValue.ToString()).Length
&& index >= 0)
{
return this[index];
}
var namestr = name.ToString();
if (namestr == "length")
return length;
return DefaultFieldGetter(name, forWrite, own); // обращение идёт к Объекту String, а не к значению string, поэтому члены создавать можно
}
示例8: valueOf
public static JSObject valueOf(JSObject self)
{
if ((self as object) is String && self.valueType == JSObjectType.Object) // prototype instance
return self.ToString();
if (self.valueType == JSObjectType.String)
return self;
else
throw new JSException(new TypeError("Try to call String.valueOf for not string object."));
}
示例9: lastIndexOf
public static JSObject lastIndexOf(JSObject self, Arguments args)
{
if (args.Length == 0)
return -1;
string fstr = args[0].ToString();
int pos = int.MaxValue >> 1;
while (args.Length > 1)
{
JSObject value = null;
switch (args[1].valueType)
{
case JSObjectType.Int:
case JSObjectType.Bool:
{
pos = args[1].iValue;
break;
}
case JSObjectType.Double:
{
if (!double.IsNaN(args[1].dValue))
pos = (int)args[1].dValue;
break;
}
case JSObjectType.Object:
case JSObjectType.Date:
case JSObjectType.Function:
{
value = args[1].ToPrimitiveValue_Value_String();
if (value.valueType < JSObjectType.String)
{
args[1] = value;
continue;
}
goto case JSObjectType.String;
}
case JSObjectType.String:
{
double d = 0;
Tools.ParseNumber((value ?? args[1]).ToString(), pos, out d, Tools.ParseNumberOptions.Default);
pos = (int)d;
break;
}
}
break;
}
var strValue = self.ToString();
return strValue.LastIndexOf(fstr, StringComparison.CurrentCulture) == 0
? 0
: strValue.LastIndexOf(fstr, System.Math.Max(0, System.Math.Min(pos, strValue.Length - 1)), StringComparison.CurrentCulture);
}
示例10: concat
public static JSObject concat(JSObject self, Arguments args)
{
if (args.length == 0)
return self.ToString();
if (args.length == 1)
return string.Concat(self.ToString(), args[0].ToString());
if (args.length == 2)
return string.Concat(self.ToString(), args[0].ToString(), args[1].ToString());
if (args.length == 3)
return string.Concat(self.ToString(), args[0].ToString(), args[1].ToString(), args[2].ToString());
if (args.length == 4)
return string.Concat(self.ToString(), args[0].ToString(), args[1].ToString(), args[2].ToString(), args[3].ToString());
var res = new StringBuilder().Append(self.ToString());
for (var i = 0; i < args.Length; i++)
res.Append(args[i].ToString());
return res.ToString();
}
示例11: DeleteMember
protected internal override bool DeleteMember(JSObject name)
{
if (members == null)
fillMembers();
string tname = null;
JSObject field = null;
if (fields != null
&& fields.TryGetValue(tname = name.ToString(), out field)
&& (!field.IsExist || (field.attributes & JSObjectAttributesInternal.DoNotDelete) == 0))
{
if ((field.attributes & JSObjectAttributesInternal.SystemObject) == 0)
field.valueType = JSObjectType.NotExistsInObject;
return fields.Remove(tname) | members.Remove(tname); // it's not mistake
}
else
{
IList<MemberInfo> m = null;
if (members.TryGetValue(tname.ToString(), out m))
{
for (var i = m.Count; i-- > 0; )
{
if (m[i].IsDefined(typeof(DoNotDeleteAttribute), false))
return false;
}
}
if (!members.Remove(tname) && prototypeInstance != null)
return _prototypeInstance.DeleteMember(tname);
}
return true;
}
示例12: GetMember
internal protected override JSObject GetMember(JSObject nameObj, bool create, bool own)
{
string name = nameObj.ToString();
JSObject r = null;
if (fields.TryGetValue(name, out r))
{
if (r.valueType < JSObjectType.Undefined)
{
if (!create)
{
var t = DefaultFieldGetter(nameObj, false, own);
if (t.IsExist)
r.Assign(t);
}
}
if (create
&& ((attributes & JSObjectAttributesInternal.Immutable) == 0)
&& (r.attributes & (JSObjectAttributesInternal.SystemObject | JSObjectAttributesInternal.ReadOnly)) == JSObjectAttributesInternal.SystemObject)
fields[name] = r = r.CloneImpl();
return r;
}
if (members == null)
fillMembers();
IList<MemberInfo> m = null;
members.TryGetValue(name, out m);
if (m == null || m.Count == 0)
{
var pi = prototypeInstance as JSObject;
if (pi != null)
return pi.GetMember(nameObj, create, own);
else
return DefaultFieldGetter(nameObj, create, own);
}
if (m.Count > 1)
{
for (int i = 0; i < m.Count; i++)
if (!(m[i] is MethodBase))
throw new JSException(Proxy(new TypeError("Incompatible fields type.")));
var cache = new MethodProxy[m.Count];
for (int i = 0; i < m.Count; i++)
cache[i] = new MethodProxy(m[i] as MethodBase);
r = new MethodGroup(cache);
}
else
{
#if PORTABLE
switch (m[0].get_MemberType())
#else
switch (m[0].MemberType)
#endif
{
case MemberTypes.Constructor:
throw new InvalidOperationException("Constructor can not be called directly");
case MemberTypes.Method:
{
var method = (MethodInfo)m[0];
r = new MethodProxy(method);
r.attributes &= ~(JSObjectAttributesInternal.ReadOnly | JSObjectAttributesInternal.DoNotDelete | JSObjectAttributesInternal.NotConfigurable | JSObjectAttributesInternal.DoNotEnum);
break;
}
case MemberTypes.Field:
{
var field = (m[0] as FieldInfo);
if ((field.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != 0
&& (field.Attributes & FieldAttributes.Static) != 0)
{
r = Proxy(field.GetValue(null));
r.attributes |= JSObjectAttributesInternal.ReadOnly;
}
else
{
r = new JSObject()
{
valueType = JSObjectType.Property,
oValue = new PropertyPair
(
new ExternalFunction((thisBind, a) =>
{
return Proxy(field.GetValue(field.IsStatic ? null : thisBind.Value));
}),
!m[0].IsDefined(typeof(Modules.ReadOnlyAttribute), false) ? new ExternalFunction((thisBind, a) =>
{
field.SetValue(field.IsStatic ? null : thisBind.Value, a[0].Value);
return null;
}) : null
)
};
r.attributes = JSObjectAttributesInternal.Immutable | JSObjectAttributesInternal.Field;
if ((r.oValue as PropertyPair).set == null)
r.attributes |= JSObjectAttributesInternal.ReadOnly;
}
break;
}
case MemberTypes.Property:
{
var pinfo = (PropertyInfo)m[0];
r = new JSObject()
{
valueType = JSObjectType.Property,
//.........这里部分代码省略.........
示例13: DeleteMember
protected internal override bool DeleteMember(JSObject name)
{
if (name.valueType == JSObjectType.Int)
{
switch (name.iValue)
{
case 0:
return a0 == null || ((a0.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a0 = null) == null;
case 1:
return a1 == null || ((a1.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a1 = null) == null;
case 2:
return a2 == null || ((a2.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a2 = null) == null;
case 3:
return a3 == null || ((a3.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a3 = null) == null;
case 4:
return a4 == null || ((a4.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a4 = null) == null;
//case 5:
// return a5 == null || ((a5.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a5 = null) == null;
//case 6:
// return a6 == null || ((a6.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a6 = null) == null;
//case 7:
// return a7 == null || ((a7.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a7 = null) == null;
}
}
switch (name.ToString())
{
case "0":
return a0 == null || ((a0.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a0 = null) == null;
case "1":
return a1 == null || ((a1.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a1 = null) == null;
case "2":
return a2 == null || ((a2.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a2 = null) == null;
case "3":
return a3 == null || ((a3.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a3 = null) == null;
case "4":
return a4 == null || ((a4.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a4 = null) == null;
//case "5":
// return a5 == null || ((a5.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a5 = null) == null;
//case "6":
// return a6 == null || ((a6.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a6 = null) == null;
//case "7":
// return a7 == null || ((a7.attributes & JSObjectAttributesInternal.DoNotDelete) == 0) && (a7 = null) == null;
}
return base.DeleteMember(name);
}
示例14: GetMember
protected internal override JSObject GetMember(JSObject name, bool createMember, bool own)
{
createMember &= (attributes & JSObjectAttributesInternal.Immutable) == 0;
if (name.valueType == JSObjectType.Int)
{
switch (name.iValue)
{
case 0:
return (a0 ?? (!createMember ? notExists : (a0 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case 1:
return (a1 ?? (!createMember ? notExists : (a1 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case 2:
return (a2 ?? (!createMember ? notExists : (a2 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case 3:
return (a3 ?? (!createMember ? notExists : (a3 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case 4:
return (a4 ?? (!createMember ? notExists : (a4 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
//case 5:
// return (a5 ?? (!createMember ? notExists : (a5 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
//case 6:
// return (a6 ?? (!createMember ? notExists : (a6 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
//case 7:
// return (a7 ?? (!createMember ? notExists : (a7 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
}
}
switch (name.ToString())
{
case "0":
return (a0 ?? (!createMember ? notExists : (a0 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case "1":
return (a1 ?? (!createMember ? notExists : (a1 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case "2":
return (a2 ?? (!createMember ? notExists : (a2 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case "3":
return (a3 ?? (!createMember ? notExists : (a3 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case "4":
return (a4 ?? (!createMember ? notExists : (a4 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
//case "5":
// return (a5 ?? (!createMember ? notExists : (a5 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
//case "6":
// return (a6 ?? (!createMember ? notExists : (a6 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
//case "7":
// return (a7 ?? (!createMember ? notExists : (a7 = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
case "length":
{
if (_length == null)
_length = new _LengthContainer(this) { valueType = JSObjectType.Int, iValue = length, attributes = JSObjectAttributesInternal.DoNotEnum | JSObjectAttributesInternal.Reassign };
return _length;
}
case "callee":
{
if (createMember && (callee.attributes & JSObjectAttributesInternal.SystemObject) != 0)
{
callee = callee.CloneImpl();
callee.attributes = JSObjectAttributesInternal.DoNotEnum;
}
return (callee ?? (!createMember ? notExists : (callee = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
}
case "caller":
{
if (createMember && (caller.attributes & JSObjectAttributesInternal.SystemObject) != 0)
{
caller = caller.CloneImpl();
callee.attributes = JSObjectAttributesInternal.DoNotEnum;
}
return (caller ?? (!createMember ? notExists : (caller = new JSObject() { valueType = JSObjectType.NotExistsInObject })));
}
}
return base.GetMember(name, createMember, own);
}
示例15: toUpperCase
public static JSObject toUpperCase(JSObject self)
{
var sstr = self.ToString();
var res = sstr.ToUpperInvariant();
if (self.valueType == JSObjectType.String && string.CompareOrdinal(sstr, res) == 0)
return self;
return res;
}