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

  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 System;
  19.     using System.Collections;
  20.     using System.Diagnostics;
  21.     using System.Reflection;
  22.    
  23.     public sealed class EnumeratorConstructor : ScriptFunction
  24.     {
  25.         static internal readonly EnumeratorConstructor ob = new EnumeratorConstructor();
  26.        
  27.         private EnumeratorPrototype originalPrototype;
  28.        
  29.         internal EnumeratorConstructor() : base(FunctionPrototype.ob, "Enumerator", 1)
  30.         {
  31.             this.originalPrototype = EnumeratorPrototype.ob;
  32.             EnumeratorPrototype._constructor = this;
  33.             this.proto = EnumeratorPrototype.ob;
  34.         }
  35.        
  36.         internal EnumeratorConstructor(LenientFunctionPrototype parent, LenientEnumeratorPrototype prototypeProp) : base(parent, "Enumerator", 1)
  37.         {
  38.             this.originalPrototype = prototypeProp;
  39.             prototypeProp.constructor = this;
  40.             this.proto = prototypeProp;
  41.             this.noExpando = false;
  42.         }
  43.        
  44.         internal override object Call(object[] args, object thisob)
  45.         {
  46.             return null;
  47.         }
  48.        
  49.         internal override object Construct(object[] args)
  50.         {
  51.             return this.CreateInstance(args);
  52.         }
  53.        
  54.         [JSFunctionAttribute(JSFunctionAttributeEnum.HasVarArgs)]
  55.         public new EnumeratorObject CreateInstance(params object[] args)
  56.         {
  57.             if (args.Length != 0) {
  58.                 object obj = args[0];
  59.                 if (obj is IEnumerable)
  60.                     return new EnumeratorObject(this.originalPrototype, (IEnumerable)obj);
  61.                 throw new JScriptException(JSError.NotCollection);
  62.             }
  63.             else
  64.                 return new EnumeratorObject(this.originalPrototype, (IEnumerable)null);
  65.         }
  66.        
  67.         public object Invoke()
  68.         {
  69.             return null;
  70.         }
  71.        
  72.     }
  73. }

Developer Fusion