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


C# IEnvironment.CheckObjectCoercible方法代码示例

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


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

示例1: Trim

 IDynamic Trim(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     s = s.Trim(Machete.Compiler.CharSets.trimCharacters);
     return environment.CreateString(s);
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:8,代码来源:PString.cs

示例2: Substring

 IDynamic Substring(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     var start = args[0];
     var end = args[1];
     var startIndex = args[0].ConvertToInteger().BaseValue;
     var endIndex = end is IUndefined ? (double)s.Length : end.ConvertToInteger().BaseValue;
     var finalStart = Math.Min(Math.Max(startIndex, 0), s.Length);
     var finalEnd = Math.Min(Math.Max(endIndex, 0), s.Length);
     var from = (int)Math.Min(finalStart, finalEnd);
     var to = (int)Math.Max(finalStart, finalEnd);
     return environment.CreateString(s.Substring(from, to - from));
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:15,代码来源:PString.cs

示例3: ToUpperCase

 IDynamic ToUpperCase(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     return environment.CreateString(s.ToUpperInvariant());
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:7,代码来源:PString.cs

示例4: Slice

 IDynamic Slice(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     var start = args[0];
     var end = args[1];
     var intStart = (int)start.ConvertToInteger().BaseValue;
     var intEnd = end is IUndefined ? s.Length : (int)end.ConvertToInteger().BaseValue;
     var from = intStart < 0 ? Math.Max(s.Length + intStart, 0) : Math.Min(intStart, s.Length);
     var to = intStart < 0 ? Math.Max(s.Length + intEnd, 0) : Math.Min(intEnd, s.Length);
     var span = Math.Max(to - from, 0);
     return environment.CreateString(s.Substring(from, span));
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:14,代码来源:PString.cs

示例5: Split

        IDynamic Split(IEnvironment environment, IArgs args)
        {
            var o = environment.Context.ThisBinding;
            environment.CheckObjectCoercible(o);
            var s = o.ConvertToString().BaseValue;
            var separatorArg = args[0];
            var limitArg = args[1];
            var array = ((IConstructable)environment.ArrayConstructor).Construct(environment, environment.EmptyArgs);

            int limit = 0, lower = 0, upper = 0, count = 0;
            IPropertyDescriptor desc;
            IString value;

            // Using int32 instead of uint32 due to limitations of .NET arrays.
            limit = limitArg is IUndefined ? int.MaxValue : (int)limitArg.ConvertToUInt32().BaseValue;
            if (limit == 0)
            {
                return array;
            }

            var separatorObj = separatorArg as NRegExp;
            if (separatorObj != null)
            {
                do
                {
                    var result = separatorObj.RegExpMatcher(s, upper);
                    if (!result.success)
                    {
                        upper++;
                    }
                    else
                    {
                        upper = result.matchState.endIndex;
                        value = environment.CreateString(s.Substring(lower, upper - lower - 1));
                        desc = environment.CreateDataDescriptor(value, true, true, true);
                        array.DefineOwnProperty(count.ToString(), desc, true);
                        if (++count == limit) return array;
                        var captures = result.matchState.captures;
                        for (int i = 0; i < captures.Length; i++)
                        {
                            value = environment.CreateString(captures[i]);
                            desc = environment.CreateDataDescriptor(value, true, true, true);
                            array.DefineOwnProperty(count.ToString(), desc, true);
                            if (++count == limit) return array;
                        }
                        lower = upper;
                    }
                } while (upper < s.Length);
                value = environment.CreateString(s.Substring(lower));
                desc = environment.CreateDataDescriptor(value, true, true, true);
                array.DefineOwnProperty(count.ToString(), desc, true);
            }
            else
            {
                var separatorStr = ((IString)separatorArg).BaseValue;
                var pieces = s.Split(new[] { separatorStr }, StringSplitOptions.None);
                for (int i = 0; i < pieces.Length; i++)
                {
                    value = environment.CreateString(pieces[i]);
                    desc = environment.CreateDataDescriptor(value, true, true, true);
                    array.DefineOwnProperty(i.ToString(), desc, true);
                    if (++count == limit) return array;
                }
            }

            return array;
        }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:67,代码来源:PString.cs

示例6: Match

 IDynamic Match(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var dynS = o.ConvertToString();
     var s = dynS.BaseValue;
     var regexpArg = args[0];
     var regexpObj = regexpArg as NRegExp;
     if (regexpObj == null)
     {
         var constructor = (IConstructable)environment.RegExpConstructor;
         var pattern = regexpArg.ConvertToString();
         regexpObj = (NRegExp)constructor.Construct(environment, environment.CreateArgs(new [] { pattern }));
     }
     var exec = ((ICallable)regexpObj.Get("exec"));
     var execArgs = environment.CreateArgs(new [] { dynS });
     if (!regexpObj.Get("global").ConvertToBoolean().BaseValue)
     {
         return exec.Call(environment, regexpObj, execArgs);
     }
     else
     {
         var constructor = (IConstructable)environment.ArrayConstructor;
         var array = constructor.Construct(environment, environment.EmptyArgs);
         var previousLastIndex = 0;
         var lastMatch = true;
         var n = 0;
         while (lastMatch)
         {
             var result = exec.Call(environment, regexpObj, execArgs);
             switch (result.TypeCode)
             {
                 case LanguageTypeCode.Null:
                     lastMatch = false;
                     break;
                 default:
                     var thisIndex = (int)regexpObj.Get("lastIndex").ConvertToNumber().BaseValue;
                     if (thisIndex == previousLastIndex)
                     {
                         thisIndex += 1;
                         regexpObj.Put("lastIndex", environment.CreateNumber(thisIndex), false);
                         previousLastIndex = thisIndex;
                     }
                     else
                     {
                         previousLastIndex = thisIndex;
                     }
                     var matchStr = ((IObject)result).Get("0");
                     var desc = environment.CreateDataDescriptor(matchStr, true, true, true);
                     array.DefineOwnProperty(n.ToString(), desc, true);
                     n++;
                     break;
             }
         }
         if (n == 0)
         {
             return environment.Null;
         }
         return array;
     }
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:61,代码来源:PString.cs

示例7: Search

 IDynamic Search(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     var regexpArg = args[0];
     var regexpObj = regexpArg as NRegExp;
     if (regexpObj == null)
     {
         var constructor = (IConstructable)environment.RegExpConstructor;
         var pattern = regexpArg.ConvertToString();
         regexpObj = (NRegExp)constructor.Construct(environment, environment.CreateArgs(new [] { pattern }));
     }
     var regExp = regexpObj.RegExpMatcher;
     var index = 0;
     do
     {
         var result = regExp(s, index);
         if (result.success)
         {
             return environment.CreateNumber(index);
         }
     } while (++index < s.Length);
     return environment.CreateNumber(-1);
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:25,代码来源:PString.cs

示例8: LocaleCompare

 IDynamic LocaleCompare(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     var that = args[0].ConvertToString().BaseValue;
     return environment.CreateNumber((double)s.CompareTo(that));
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:8,代码来源:PString.cs

示例9: LastIndexOf

 IDynamic LastIndexOf(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     var searchString = args[0].ConvertToString().BaseValue;
     var position = args.Count > 1 ? (int)args[1].ConvertToInteger().BaseValue : int.MaxValue;
     var start = Math.Min(Math.Max(position, 0), s.Length);
     return environment.CreateNumber((double)s.LastIndexOf(searchString, start));
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:10,代码来源:PString.cs

示例10: Concat

 IDynamic Concat(IEnvironment environment, IArgs args)
 {
     var sb = new StringBuilder();
     {
         var o = environment.Context.ThisBinding;
         environment.CheckObjectCoercible(o);
         sb.Append(o.ConvertToString().BaseValue);
         foreach (var arg in args)
         {
             sb.Append(arg.ConvertToString().BaseValue);
         }
     }
     return environment.CreateString(sb.ToString());
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:14,代码来源:PString.cs

示例11: CharCodeAt

 IDynamic CharCodeAt(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     var position = (int)args[0].ConvertToInteger().BaseValue;
     if (position < 0 || position >= s.Length)
     {
         return environment.CreateNumber(double.NaN);
     }
     return environment.CreateNumber((double)s[position]);
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:12,代码来源:PString.cs

示例12: CharAt

 IDynamic CharAt(IEnvironment environment, IArgs args)
 {
     var o = environment.Context.ThisBinding;
     environment.CheckObjectCoercible(o);
     var s = o.ConvertToString().BaseValue;
     var position = (int)args[0].ConvertToInteger().BaseValue;
     if (position < 0 || position >= s.Length)
     {
         return environment.CreateString(string.Empty);
     }
     return environment.CreateString(s.Substring(position, 1));
 }
开发者ID:ChaosPandion,项目名称:Machete,代码行数:12,代码来源:PString.cs


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