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

  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.Globalization;
  20.     using System.Reflection;
  21.    
  22.     internal sealed class JSClosureField : JSVariableField
  23.     {
  24.         internal FieldInfo field;
  25.         //Used to indicate that the field is accessed from a nested (static) function.
  26.         internal JSClosureField(FieldInfo field) : base(field.Name, null, field.Attributes | FieldAttributes.Static)
  27.         {
  28.             //Fool the analysis code to OK calls to this method from static code
  29.             if (field is JSFieldInfo)
  30.                 field = ((JSFieldInfo)field).field;
  31.             this.field = field;
  32.         }
  33.        
  34.         public override Type DeclaringType {
  35.             get { return this.field.DeclaringType; }
  36.         }
  37.        
  38.         public override Type FieldType {
  39.             get { return this.field.FieldType; }
  40.         }
  41.        
  42.         internal override IReflect GetInferredType(JSField inference_target)
  43.         {
  44.             if (this.field is JSMemberField)
  45.                 return ((JSMemberField)this.field).GetInferredType(inference_target);
  46.             else
  47.                 return this.field.FieldType;
  48.         }
  49.        
  50.         internal override object GetMetaData()
  51.         {
  52.             if (this.field is JSField)
  53.                 return ((JSField)this.field).GetMetaData();
  54.             else
  55.                 return this.field;
  56.         }
  57.        
  58.         public override object GetValue(object obj)
  59.         {
  60.             if (obj is StackFrame)
  61.                 return this.field.GetValue(((StackFrame)((StackFrame)obj).engine.ScriptObjectStackTop()).closureInstance);
  62.             throw new JScriptException(JSError.InternalError);
  63.             //should never happen
  64.         }
  65.        
  66.         public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo locale)
  67.         {
  68.             if (obj is StackFrame) {
  69.                 this.field.SetValue(((StackFrame)((StackFrame)obj).engine.ScriptObjectStackTop()).closureInstance, value, invokeAttr, binder, locale);
  70.                 return;
  71.             }
  72.             throw new JScriptException(JSError.InternalError);
  73.             //should never happen
  74.         }
  75.     }
  76. }

Developer Fusion