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

  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 JSGlobalField : JSVariableField
  23.     {
  24.         internal FieldInfo ILField;
  25.         //Used for named items
  26.         internal JSGlobalField(ScriptObject obj, string name, object value, FieldAttributes attributeFlags) : base(name, obj, attributeFlags)
  27.         {
  28.             this.value = value;
  29.             this.ILField = null;
  30.         }
  31.        
  32.         public override object GetValue(object obj)
  33.         {
  34.             if (this.ILField == null)
  35.                 return this.value;
  36.             return this.ILField.GetValue(null);
  37.         }
  38.        
  39.         public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
  40.         {
  41.             if (this.ILField != null) {
  42.                 this.ILField.SetValue(null, value, invokeAttr, binder, culture);
  43.                 return;
  44.             }
  45.             if ((this.IsLiteral || this.IsInitOnly) && !(this.value is Missing)) {
  46.                 if (this.value is FunctionObject && value is FunctionObject && this.Name.Equals(((FunctionObject)value).name)) {
  47.                     this.value = value;
  48.                     return;
  49.                 }
  50.                 throw new JScriptException(JSError.AssignmentToReadOnly);
  51.             }
  52.             if (this.type != null)
  53.                 this.value = Convert.Coerce(value, this.type);
  54.             else
  55.                 this.value = value;
  56.         }
  57.     }
  58. }

Developer Fusion