本文整理汇总了C#中JsDictionaryObject.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JsDictionaryObject.ToString方法的具体用法?C# JsDictionaryObject.ToString怎么用?C# JsDictionaryObject.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsDictionaryObject
的用法示例。
在下文中一共展示了JsDictionaryObject.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConcatImpl
/// <summary>
/// 15.5.4.6
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public JsInstance ConcatImpl(JsDictionaryObject target, JsInstance[] parameters)
{
StringBuilder sb = new StringBuilder();
sb.Append(target.ToString());
for (int i = 0; i < parameters.Length; i++) {
sb.Append(parameters[i].ToString());
}
return Global.StringClass.New(sb.ToString());
}
示例2: CharCodeAtImpl
/// <summary>
/// 15.5.4.5
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance CharCodeAtImpl(JsDictionaryObject target, JsInstance[] parameters)
{
var r = target.ToString();
var at = (int)parameters[0].ToNumber();
if (r == String.Empty || at > r.Length - 1) {
return Global.NaN;
}
else {
return Global.NumberClass.New(Convert.ToInt32(r[at]));
}
}
示例3: ToLocaleUpperCaseImpl
/// <summary>
/// 15.5.4.19
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance ToLocaleUpperCaseImpl(JsDictionaryObject target, JsInstance[] parameters) {
string str = target.ToString();
return Global.StringClass.New(str.ToUpper());
}
示例4: ToUpperCaseImpl
/// <summary>
/// 15.5.4.18
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance ToUpperCaseImpl(JsDictionaryObject target, JsInstance[] parameters) {
return Global.StringClass.New(target.ToString().ToUpperInvariant());
}
示例5: ToLocaleLowerCaseImpl
/// <summary>
/// 15.5.4.17
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance ToLocaleLowerCaseImpl(JsDictionaryObject target, JsInstance[] parameters) {
return Global.StringClass.New(target.ToString().ToLower());
}
示例6: SubstrImpl
public JsInstance SubstrImpl(JsDictionaryObject target, JsInstance[] parameters) {
string str = target.ToString();
int start = 0, end = str.Length;
if (parameters.Length > 0 && !double.IsNaN(parameters[0].ToNumber())) {
start = Convert.ToInt32(parameters[0].ToNumber());
}
if (parameters.Length > 1 && parameters[1] != JsUndefined.Instance && !double.IsNaN(parameters[1].ToNumber())) {
end = Convert.ToInt32(parameters[1].ToNumber());
}
start = Math.Min(Math.Max(start, 0), Math.Max(0, str.Length - 1));
end = Math.Min(Math.Max(end, 0), str.Length);
str = str.Substring(start, end);
return New(str);
}
示例7: SplitImpl
/// <summary>
/// 15.5.4.14
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance SplitImpl(JsDictionaryObject target, JsInstance[] parameters) {
JsObject A = Global.ArrayClass.New();
string S = target.ToString();
if (parameters.Length == 0 || parameters[0] == JsUndefined.Instance) {
A["0"] = Global.StringClass.New(S);
}
JsInstance separator = parameters[0];
int limit = parameters.Length > 1 ? Convert.ToInt32(parameters[1].ToNumber()) : Int32.MaxValue;
int s = S.Length;
string[] result;
if (separator.Class == JsInstance.CLASS_REGEXP) {
result = ((JsRegExp)parameters[0]).Regex.Split(S, limit);
}
else {
result = S.Split(new string[] { separator.ToString() }, limit, StringSplitOptions.None);
}
for (int i = 0; i < result.Length; i++) {
A[i.ToString()] = Global.StringClass.New(result[i]);
}
return A;
}
示例8: SliceImpl
/// <summary>
/// 15.5.4.13
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance SliceImpl(JsDictionaryObject target, JsInstance[] parameters) {
string source = target.ToString();
int start = (int)parameters[0].ToNumber();
int end = source.Length;
if (parameters.Length > 1) {
end = (int)parameters[1].ToNumber();
if (end < 0) {
end = source.Length + end;
}
}
if (start < 0) {
start = source.Length + start;
}
return Global.StringClass.New(source.Substring(start, end - start));
}
示例9: SearchImpl
/// <summary>
/// 15.5.4.12
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance SearchImpl(JsDictionaryObject target, JsInstance[] parameters)
{
// Converts the parameters to a regex
if (parameters[0].Class == JsString.TYPEOF)
{
parameters[0] = Global.RegExpClass.New(parameters[0].ToString(), false, false, false);
}
Match m = ((Regex)(parameters[0].Value)).Match(target.ToString());
if (m != null)
{
return Global.NumberClass.New(m.Index);
}
else
{
return Global.NumberClass.New(-1);
}
}
示例10: ReplaceImpl
/// <summary>
/// 15.5.4.11
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance ReplaceImpl(JsDictionaryObject target, JsInstance[] parameters) {
if (parameters.Length == 0) {
return Global.StringClass.New(target.ToString());
}
JsInstance searchValue = parameters[0];
JsInstance replaceValue = JsUndefined.Instance;
if (parameters.Length > 1) {
replaceValue = parameters[1];
}
string source = target.ToString();
JsFunction function = replaceValue as JsFunction;
if (searchValue.Class == JsInstance.CLASS_REGEXP) {
int count = ((JsRegExp)parameters[0]).IsGlobal ? int.MaxValue : 1;
var regexp = ((JsRegExp)parameters[0]);
int lastIndex = regexp.IsGlobal ? 0 : Math.Max(0, (int)regexp["lastIndex"].ToNumber() - 1);
if (regexp.IsGlobal) {
regexp["lastIndex"] = Global.NumberClass.New(0);
}
if (replaceValue is JsFunction)
{
string ret = ((JsRegExp)parameters[0]).Regex.Replace(source, delegate(Match m) {
List<JsInstance> replaceParameters = new List<JsInstance>();
if (!regexp.IsGlobal) {
regexp["lastIndex"] = Global.NumberClass.New(m.Index + 1);
}
replaceParameters.Add(Global.StringClass.New(m.Value));
for (int i = 1; i < m.Groups.Count; i++) {
if (m.Groups[i].Success) {
replaceParameters.Add(Global.StringClass.New(m.Groups[i].Value));
}
else {
replaceParameters.Add(JsUndefined.Instance);
}
}
replaceParameters.Add(Global.NumberClass.New(m.Index));
replaceParameters.Add(Global.StringClass.New(source));
Global.Visitor.ExecuteFunction(function, null, replaceParameters.ToArray());
return Global.Visitor.Returned.ToString();
}, count, lastIndex);
return Global.StringClass.New(ret);
}
else {
string str = parameters[1].ToString();
string ret = ((JsRegExp)parameters[0]).Regex.Replace(target.ToString(), delegate(Match m) {
if (!regexp.IsGlobal) {
regexp["lastIndex"] = Global.NumberClass.New(m.Index + 1);
}
string after = source.Substring(Math.Min(source.Length - 1, m.Index + m.Length));
return EvaluateReplacePattern(m.Value, source.Substring(0, m.Index), after, str, m.Groups);
}, count, lastIndex);
return Global.StringClass.New(ret);
}
}
else {
string search = searchValue.ToString();
int index = source.IndexOf(search);
if (index != -1) {
if (replaceValue is JsFunction)
{
List<JsInstance> replaceParameters = new List<JsInstance>();
replaceParameters.Add(Global.StringClass.New(search));
replaceParameters.Add(Global.NumberClass.New(index));
replaceParameters.Add(Global.StringClass.New(source));
Global.Visitor.ExecuteFunction(function, null, replaceParameters.ToArray());
replaceValue = Global.Visitor.Result;
return Global.StringClass.New(source.Substring(0, index) + replaceValue.ToString() + source.Substring(index + search.Length));
}
else {
string before = source.Substring(0, index);
string after = source.Substring(index + search.Length);
string newString = EvaluateReplacePattern(search, before, after, replaceValue.ToString(), null);
return Global.StringClass.New(before + newString + after);
}
}
else {
return Global.StringClass.New(source);
//.........这里部分代码省略.........
示例11: MatchFunc
/// <summary>
/// 15.5.4.10
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance MatchFunc(JsDictionaryObject target, JsInstance[] parameters)
{
JsRegExp regexp = parameters[0].Class == JsInstance.CLASS_STRING
? Global.RegExpClass.New(parameters[0].ToString(), false, false, false)
: (JsRegExp)parameters[0];
if (!regexp.IsGlobal)
{
return Global.RegExpClass.ExecImpl(regexp, new JsInstance[] {target});
}
else
{
var result = Global.ArrayClass.New();
var matches = Regex.Matches(target.ToString(), regexp.Pattern, regexp.Options);
if (matches.Count > 0)
{
var i = 0;
foreach (Match match in matches)
{
result[Global.NumberClass.New(i++)] = Global.StringClass.New(match.Value);
}
return result;
}
else
{
return JsNull.Instance;
}
}
}
示例12: LocaleCompareImpl
/// <summary>
/// 15.5.4.9
/// </summary>
/// <param name="target"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public JsInstance LocaleCompareImpl(JsDictionaryObject target, JsInstance[] parameters) {
return Global.NumberClass.New(target.ToString().CompareTo(parameters[0].ToString()));
}
示例13: LastIndexOfImpl
/// <summary>
/// 15.5.4.8
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public JsInstance LastIndexOfImpl(JsDictionaryObject target, JsInstance[] parameters) {
string source = target.ToString();
string searchString = parameters[0].ToString();
int position = parameters.Length > 1 ? (int)parameters[1].ToNumber() : source.Length;
return Global.NumberClass.New(source.Substring(0, position).LastIndexOf(searchString));
}
示例14: IndexOfImpl
/// <summary>
/// 15.5.4.7
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public JsInstance IndexOfImpl(JsDictionaryObject target, JsInstance[] parameters) {
string source = target.ToString();
string searchString = parameters[0].ToString();
int position = parameters.Length > 1 ? (int)parameters[1].ToNumber() : 0;
if (searchString == String.Empty) {
if (parameters.Length > 1) {
return Global.NumberClass.New(Math.Min(source.Length, position));
}
else {
return Global.NumberClass.New(0);
}
}
if (position >= source.Length) {
return Global.NumberClass.New(-1);
}
return Global.NumberClass.New(source.IndexOf(searchString, position));
}
示例15: LengthImpl
/// <summary>
/// 15.5.5.1
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public JsInstance LengthImpl(JsDictionaryObject target) {
string str = target.ToString();
return Global.NumberClass.New(str.Length);
}