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

  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. //This class is a compile time helper only. It is used by class definitions marked as expando. The evaluator never sees instances of this class.
  16. namespace Microsoft.JScript
  17. {
  18.    
  19.     using System;
  20.     using System.Reflection;
  21.     using System.Globalization;
  22.     using System.Diagnostics;
  23.    
  24.     internal sealed class JSExpandoIndexerMethod : JSMethod
  25.     {
  26.         private ClassScope classScope;
  27.         private bool isGetter;
  28.         private MethodInfo token;
  29.        
  30.         private ParameterInfo[] GetterParams;
  31.         private ParameterInfo[] SetterParams;
  32.        
  33.         internal JSExpandoIndexerMethod(ClassScope classScope, bool isGetter) : base(null)
  34.         {
  35.             //The object is never used, but it is convenient to have the field on JSMethod.
  36.             this.isGetter = isGetter;
  37.             this.classScope = classScope;
  38.            
  39.             this.GetterParams = new ParameterInfo[] {new ParameterDeclaration(Typeob.String, "field")};
  40.             this.SetterParams = new ParameterInfo[] {new ParameterDeclaration(Typeob.String, "field"), new ParameterDeclaration(Typeob.Object, "value")};
  41.         }
  42.        
  43.         internal override object Construct(object[] args)
  44.         {
  45.             throw new JScriptException(JSError.InvalidCall);
  46.         }
  47.        
  48.         public override MethodAttributes Attributes {
  49.             get { return MethodAttributes.Public; }
  50.         }
  51.        
  52.         public override Type DeclaringType {
  53.             get { return this.classScope.GetTypeBuilderOrEnumBuilder(); }
  54.         }
  55.        
  56.         public override ParameterInfo[] GetParameters()
  57.         {
  58.             if (this.isGetter)
  59.                 return this.GetterParams;
  60.             else
  61.                 return this.SetterParams;
  62.         }
  63.        
  64.         internal override MethodInfo GetMethodInfo(CompilerGlobals compilerGlobals)
  65.         {
  66.             if (this.isGetter) {
  67.                 if (this.token == null)
  68.                     this.token = this.classScope.owner.GetExpandoIndexerGetter();
  69.             }
  70.             else {
  71.                 if (this.token == null)
  72.                     this.token = this.classScope.owner.GetExpandoIndexerSetter();
  73.             }
  74.             return this.token;
  75.         }
  76.        
  77.         #if !DEBUG
  78.         [DebuggerStepThroughAttribute()]
  79.         [DebuggerHiddenAttribute()]
  80.         #endif
  81.         internal override object Invoke(object obj, object thisob, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
  82.         {
  83.             throw new JScriptException(JSError.InvalidCall);
  84.         }
  85.        
  86.         public override string Name {
  87.             get {
  88.                 if (this.isGetter)
  89.                     return "get_Item";
  90.                 else
  91.                     return "set_Item";
  92.             }
  93.         }
  94.        
  95.         public override Type ReturnType {
  96.             get {
  97.                 if (this.isGetter)
  98.                     return Typeob.Object;
  99.                 else
  100.                     return Typeob.Void;
  101.             }
  102.         }
  103.     }
  104.    
  105. }

Developer Fusion