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

  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.Globalization;
  21.     using System.Reflection;
  22.    
  23.     public sealed class JSFieldInfo : FieldInfo
  24.     {
  25.         internal FieldInfo field;
  26.         private FieldAttributes attributes;
  27.         private Type declaringType = null;
  28.         private Type fieldType = null;
  29.         private FieldAccessor fieldAccessor = null;
  30.        
  31.         internal JSFieldInfo(FieldInfo field)
  32.         {
  33.             this.field = field;
  34.             this.attributes = field.Attributes;
  35.         }
  36.        
  37.         public override FieldAttributes Attributes {
  38.             get { return this.attributes; }
  39.         }
  40.        
  41.         public override Type DeclaringType {
  42.             get {
  43.                 Type result = this.declaringType;
  44.                 if (result == null)
  45.                     this.declaringType = result = this.field.DeclaringType;
  46.                 return result;
  47.             }
  48.         }
  49.        
  50.         public override RuntimeFieldHandle FieldHandle {
  51.             get { return this.field.FieldHandle; }
  52.         }
  53.        
  54.         public override Type FieldType {
  55.             get {
  56.                 Type result = this.fieldType;
  57.                 if (result == null)
  58.                     this.fieldType = result = this.field.FieldType;
  59.                 return result;
  60.             }
  61.         }
  62.        
  63.         public override object[] GetCustomAttributes(Type t, bool inherit)
  64.         {
  65.             return new FieldInfo[0];
  66.         }
  67.        
  68.         public override object[] GetCustomAttributes(bool inherit)
  69.         {
  70.             return new FieldInfo[0];
  71.         }
  72.        
  73.         public override object GetValue(object obj)
  74.         {
  75.             FieldAccessor accessor = this.fieldAccessor;
  76.             if (accessor == null)
  77.                 this.fieldAccessor = accessor = FieldAccessor.GetAccessorFor(TypeReferences.ToExecutionContext(this.field));
  78.             return accessor.GetValue(obj);
  79.         }
  80.        
  81.         public override bool IsDefined(Type type, bool inherit)
  82.         {
  83.             return false;
  84.         }
  85.        
  86.         public override MemberTypes MemberType {
  87.             get { return MemberTypes.Field; }
  88.         }
  89.        
  90.         public override string Name {
  91.             get { return this.field.Name; }
  92.         }
  93.        
  94.         public override Type ReflectedType {
  95.             get { return this.field.ReflectedType; }
  96.         }
  97.        
  98.         public new void SetValue(object obj, object value)
  99.         {
  100.             if ((this.attributes & FieldAttributes.InitOnly) != 0)
  101.                 throw new JScriptException(JSError.AssignmentToReadOnly);
  102.             this.SetValue(obj, value, BindingFlags.SetField, null, null);
  103.         }
  104.        
  105.         public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
  106.         {
  107.             Debug.PreCondition(binder == null && culture == null);
  108.             FieldAccessor accessor = this.fieldAccessor;
  109.             if (accessor == null)
  110.                 this.fieldAccessor = accessor = FieldAccessor.GetAccessorFor(this.field);
  111.             accessor.SetValue(obj, value);
  112.         }
  113.        
  114.     }
  115. }

Developer Fusion