The Labs \ Source Viewer \ SSCLI \ Microsoft.JScript \ VBArrayObject

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. namespace Microsoft.JScript
  16. {
  17.    
  18.     using Microsoft.JScript.Vsa;
  19.     using System;
  20.     using System.Collections;
  21.    
  22.     public class VBArrayObject : JSObject
  23.     {
  24.         private Array array;
  25.        
  26.         public VBArrayObject(VBArrayPrototype parent, Array array) : base(parent)
  27.         {
  28.             this.array = array;
  29.             this.noExpando = false;
  30.         }
  31.        
  32.         internal virtual int dimensions()
  33.         {
  34.             return this.array.Rank;
  35.         }
  36.        
  37.         internal virtual object getItem(object[] args)
  38.         {
  39.             if (args == null || args.Length == 0)
  40.                 throw new JScriptException(JSError.TooFewParameters);
  41.             if (args.Length == 1)
  42.                 return this.array.GetValue(Convert.ToInt32(args[0]));
  43.             if (args.Length == 2)
  44.                 return this.array.GetValue(Convert.ToInt32(args[0]), Convert.ToInt32(args[1]));
  45.             if (args.Length == 3)
  46.                 return this.array.GetValue(Convert.ToInt32(args[0]), Convert.ToInt32(args[1]), Convert.ToInt32(args[2]));
  47.             int n = args.Length;
  48.             int[] intArgs = new int[n];
  49.             for (int i = 0; i < n; i++)
  50.                 intArgs[i] = Convert.ToInt32(args[i]);
  51.             return this.array.GetValue(intArgs);
  52.         }
  53.        
  54.         internal virtual int lbound(object dimension)
  55.         {
  56.             int dim = Convert.ToInt32(dimension);
  57.             return this.array.GetLowerBound(dim);
  58.         }
  59.        
  60.         internal virtual ArrayObject toArray(VsaEngine engine)
  61.         {
  62.             IList aList = this.array;
  63.             ArrayObject result = engine.GetOriginalArrayConstructor().Construct();
  64.             uint i = 0;
  65.             int n = aList.Count;
  66.             IEnumerator e = aList.GetEnumerator();
  67.             result.length = n;
  68.             while (e.MoveNext())
  69.                 result.SetValueAtIndex(i++, e.Current);
  70.             return result;
  71.         }
  72.        
  73.         internal virtual int ubound(object dimension)
  74.         {
  75.             int dim = Convert.ToInt32(dimension);
  76.             return this.array.GetUpperBound(dim);
  77.         }
  78.        
  79.     }
  80. }

Developer Fusion