当前位置: 首页>>代码示例>>C#>>正文


C# JSObject.ToPrimitiveValue_Value_String方法代码示例

本文整理汇总了C#中JSObject.ToPrimitiveValue_Value_String方法的典型用法代码示例。如果您正苦于以下问题:C# JSObject.ToPrimitiveValue_Value_String方法的具体用法?C# JSObject.ToPrimitiveValue_Value_String怎么用?C# JSObject.ToPrimitiveValue_Value_String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSObject的用法示例。


在下文中一共展示了JSObject.ToPrimitiveValue_Value_String方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: split

 public static JSObject split(JSObject self, Arguments args)
 {
     if (args.Length == 0 || !args[0].IsDefinded)
         return new Array(new object[] { self.ToString() });
     uint limit = uint.MaxValue;
     if (args.Length > 1)
     {
         var limO = args[1];
         if (limO.valueType >= JSObjectType.Object)
             limO = limO.ToPrimitiveValue_Value_String();
         switch (limO.valueType)
         {
             case JSObjectType.Int:
             case JSObjectType.Bool:
                 {
                     limit = (uint)limO.iValue;
                     break;
                 }
             case JSObjectType.Double:
                 {
                     limit = (uint)limO.dValue;
                     break;
                 }
             case JSObjectType.Object:
             case JSObjectType.Date:
             case JSObjectType.Function:
             case JSObjectType.String:
                 {
                     double d;
                     Tools.ParseNumber(limO.ToString(), 0, out d, Tools.ParseNumberOptions.Default);
                     limit = (uint)d;
                     break;
                 }
         }
     }
     if (args[0].valueType == JSObjectType.Object && args[0].oValue is RegExp)
     {
         string selfString = self.ToPrimitiveValue_Value_String().ToString();
         var match = (args[0].oValue as RegExp).regEx.Match(selfString);
         if ((args[0].oValue as RegExp).regEx.ToString().Length == 0)
         {
             match = match.NextMatch();
             if (limit == uint.MaxValue)
                 limit = (uint)selfString.Length;
         }
         Array res = new Array();
         int index = 0;
         while (res.data.Length < limit)
         {
             if (!match.Success)
             {
                 res.data.Add(selfString.Substring(index, selfString.Length - index));
                 break;
             }
             int nindex = match.Index;
             if (nindex == -1)
             {
                 res.data.Add(selfString.Substring(index, selfString.Length - index));
                 break;
             }
             else
             {
                 var item = selfString.Substring(index, nindex - index);
                 res.data.Add(item);
                 index = nindex + match.Length;
             }
             match = match.NextMatch();
         }
         return res;
     }
     else
     {
         string fstr = args[0].ToString();
         string selfString = self.ToPrimitiveValue_Value_String().ToString();
         Array res = new Array();
         if (string.IsNullOrEmpty(fstr))
         {
             for (var i = 0; i < System.Math.Min(selfString.Length, limit); i++)
                 res.data.Add(selfString[i]);
         }
         else
         {
             int index = 0;
             while (res.data.Length < limit)
             {
                 int nindex = selfString.IndexOf(fstr, index);
                 if (nindex == -1)
                 {
                     res.data.Add(selfString.Substring(index, selfString.Length - index));
                     break;
                 }
                 else
                 {
                     var item = selfString.Substring(index, nindex - index);
                     res.data.Add(item);
                     index = nindex + fstr.Length;
                 }
             }
         }
         return res;
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:NiL.JS,代码行数:101,代码来源:String.cs

示例2: substring

 public static JSObject substring(JSObject self, Arguments args)
 {
     string selfString = self.ToPrimitiveValue_Value_String().ToString();
     if (args.Length == 0)
         return selfString;
     int pos0 = 0;
     switch (args[0].valueType)
     {
         case JSObjectType.Int:
         case JSObjectType.Bool:
             {
                 pos0 = args[0].iValue;
                 break;
             }
         case JSObjectType.Double:
             {
                 if (double.IsNaN(args[0].dValue) || double.IsNegativeInfinity(args[0].dValue))
                     pos0 = 0;
                 else if (double.IsPositiveInfinity(args[0].dValue))
                     pos0 = selfString.Length;
                 else
                     pos0 = (int)args[0].dValue;
                 break;
             }
         case JSObjectType.Object:
         case JSObjectType.Date:
         case JSObjectType.Function:
         case JSObjectType.String:
             {
                 pos0 = Tools.JSObjectToInt32(args[0], 0, true);
                 break;
             }
     }
     int pos1 = 0;
     if (args.Length > 1)
     {
         switch (args[1].valueType)
         {
             case JSObjectType.Int:
             case JSObjectType.Bool:
                 {
                     pos1 = args[1].iValue;
                     break;
                 }
             case JSObjectType.Double:
                 {
                     if (double.IsNaN(args[1].dValue) || double.IsNegativeInfinity(args[0].dValue))
                         pos1 = 0;
                     else if (double.IsPositiveInfinity(args[1].dValue))
                         pos1 = selfString.Length;
                     else
                         pos1 = (int)args[1].dValue;
                     break;
                 }
             case JSObjectType.Object:
             case JSObjectType.Date:
             case JSObjectType.Function:
             case JSObjectType.String:
                 {
                     pos1 = Tools.JSObjectToInt32(args[1], 0, true);
                     break;
                 }
             case JSObjectType.NotExists:
             case JSObjectType.NotExistsInObject:
             case JSObjectType.Undefined:
                 {
                     pos1 = selfString.Length;
                     break;
                 }
         }
     }
     else
         pos1 = selfString.Length;
     if (pos0 > pos1)
     {
         pos0 ^= pos1;
         pos1 ^= pos0;
         pos0 ^= pos1;
     }
     pos0 = System.Math.Max(0, System.Math.Min(pos0, selfString.Length));
     pos1 = System.Math.Max(0, System.Math.Min(pos1, selfString.Length));
     return selfString.Substring(pos0, System.Math.Min(selfString.Length, System.Math.Max(0, pos1 - pos0)));
 }
开发者ID:modulexcite,项目名称:NiL.JS,代码行数:83,代码来源:String.cs

示例3: slice

 public static JSObject slice(JSObject self, Arguments args)
 {
     string selfString = self.ToPrimitiveValue_Value_String().ToString();
     if (args.Length == 0)
         return selfString;
     int pos0 = 0;
     switch (args[0].valueType)
     {
         case JSObjectType.Int:
         case JSObjectType.Bool:
             {
                 pos0 = args[0].iValue;
                 break;
             }
         case JSObjectType.Double:
             {
                 if (double.IsNaN(args[0].dValue) || double.IsNegativeInfinity(args[0].dValue))
                     pos0 = 0;
                 else if (double.IsPositiveInfinity(args[0].dValue))
                     pos0 = selfString.Length;
                 else
                     pos0 = (int)args[0].dValue;
                 break;
             }
         case JSObjectType.Object:
         case JSObjectType.Date:
         case JSObjectType.Function:
         case JSObjectType.String:
             {
                 pos0 = Tools.JSObjectToInt32(args[0], 0, true);
                 break;
             }
     }
     int pos1 = 0;
     if (args.Length > 1)
     {
         switch (args[1].valueType)
         {
             case JSObjectType.Int:
             case JSObjectType.Bool:
                 {
                     pos1 = args[1].iValue;
                     break;
                 }
             case JSObjectType.Double:
                 {
                     if (double.IsNaN(args[1].dValue) || double.IsNegativeInfinity(args[0].dValue))
                         pos1 = 0;
                     else if (double.IsPositiveInfinity(args[1].dValue))
                         pos1 = selfString.Length;
                     else
                         pos1 = (int)args[1].dValue;
                     break;
                 }
             case JSObjectType.Object:
             case JSObjectType.Date:
             case JSObjectType.Function:
             case JSObjectType.String:
                 {
                     //double d;
                     //Tools.ParseNumber(args[1].ToPrimitiveValue_Value_String().ToString(), pos1, out d, Tools.ParseNumberOptions.Default);
                     //pos1 = (int)d;
                     pos1 = Tools.JSObjectToInt32(args[1], 0, true);
                     break;
                 }
             case JSObjectType.NotExists:
             case JSObjectType.NotExistsInObject:
             case JSObjectType.Undefined:
                 {
                     pos1 = selfString.Length;
                     break;
                 }
         }
     }
     else
         pos1 = selfString.Length;
     while (pos0 < 0)
         pos0 += selfString.Length;
     while (pos1 < 0)
         pos1 += selfString.Length;
     pos0 = System.Math.Min(pos0, selfString.Length);
     return selfString.Substring(pos0, System.Math.Min(selfString.Length, System.Math.Max(0, pos1 - pos0)));
 }
开发者ID:modulexcite,项目名称:NiL.JS,代码行数:83,代码来源:String.cs


注:本文中的JSObject.ToPrimitiveValue_Value_String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。