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

  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.Reflection;
  20.     using System.Globalization;
  21.    
  22.     internal class JSClosureProperty : JSWrappedProperty
  23.     {
  24.         private MethodInfo getMeth;
  25.         private MethodInfo setMeth;
  26.        
  27.         internal JSClosureProperty(PropertyInfo property, MethodInfo getMeth, MethodInfo setMeth) : base(property, null)
  28.         {
  29.             this.getMeth = getMeth;
  30.             this.setMeth = setMeth;
  31.         }
  32.        
  33.         public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
  34.         {
  35.             if (this.getMeth == null)
  36.                 throw new MissingMethodException();
  37.             return this.getMeth.Invoke(obj, invokeAttr, binder, index, culture);
  38.         }
  39.        
  40.         public override MethodInfo GetGetMethod(bool nonPublic)
  41.         {
  42.             if (nonPublic || (this.getMeth != null && this.getMeth.IsPublic))
  43.                 return this.getMeth;
  44.             else
  45.                 return null;
  46.         }
  47.        
  48.         public override MethodInfo GetSetMethod(bool nonPublic)
  49.         {
  50.             if (nonPublic || (this.setMeth != null && this.setMeth.IsPublic))
  51.                 return this.setMeth;
  52.             else
  53.                 return null;
  54.         }
  55.        
  56.         public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
  57.         {
  58.             if (this.setMeth == null)
  59.                 throw new MissingMethodException();
  60.             int n = index == null ? 0 : index.Length;
  61.             object[] pars = new object[n + 1];
  62.             pars[0] = value;
  63.             if (n > 0)
  64.                 ArrayObject.Copy(index, 0, pars, 1, n);
  65.             this.setMeth.Invoke(obj, invokeAttr, binder, pars, culture);
  66.         }
  67.        
  68.     }
  69. }

Developer Fusion