Microsoft.JScript.LateBinding.GetValueAtIndex C# (CSharp) Method

GetValueAtIndex() private method

private GetValueAtIndex ( Object obj, ulong index ) : Object
obj Object
index ulong
return Object
      internal static Object GetValueAtIndex(Object obj, ulong index){
        if (obj is ScriptObject)
          if (index < UInt32.MaxValue)
            return ((ScriptObject)obj).GetValueAtIndex((uint)index);
          else
            return ((ScriptObject)obj).GetMemberValue(index.ToString(CultureInfo.InvariantCulture));
      default_property_case:
        if (obj is IList)
          checked {return ((IList)obj)[(int)index];}
        if (obj is Array)
          checked {return ((Array)obj).GetValue((int)index);}
        Type type = obj.GetType();
        if (type.IsCOMObject || obj is IReflect || index > Int32.MaxValue)
          return LateBinding.GetMemberValue(obj, index.ToString(CultureInfo.InvariantCulture));

        //Assume that the object does not itself have a field/property with numerical name.
        //See if the object has a default indexed property, or default property that results in an Array or List and work with that.
        MethodInfo getter = JSBinder.GetDefaultPropertyForArrayIndex(type, (int)index, null, false);
        if (getter != null){
          ParameterInfo[] pars = getter.GetParameters();
          if (pars == null || pars.Length == 0){
            obj = getter.Invoke(obj, BindingFlags.SuppressChangeType, null, null, null);
            goto default_property_case;
          }else
            return getter.Invoke(obj, (BindingFlags)0, JSBinder.ob, new Object[]{(int)index}, null);
        }

        return Missing.Value;
      }

Usage Example

        public static Object unshift(Object thisob, params Object[] args)
        {
            if (args == null || args.Length == 0)
            {
                return(thisob);
            }
            if (thisob is ArrayObject)
            {
                return(((ArrayObject)thisob).Unshift(args));
            }
            uint oldLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length"));
            long newLength = oldLength + args.Length;

            LateBinding.SetMemberValue(thisob, "length", newLength);
            // shift the array
            for (long i = oldLength - 1; i >= 0; i--)
            {
                Object val = LateBinding.GetValueAtIndex(thisob, (ulong)i);
                if (val is Missing)
                {
                    LateBinding.DeleteValueAtIndex(thisob, (ulong)(i + args.Length));
                }
                else
                {
                    LateBinding.SetValueAtIndex(thisob, (ulong)(i + args.Length), val);
                }
            }
            // copy the input args
            for (uint i = 0; i < args.Length; i++)
            {
                LateBinding.SetValueAtIndex(thisob, i, args[i]);
            }
            return(thisob);
        }
All Usage Examples Of Microsoft.JScript.LateBinding::GetValueAtIndex