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

  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 JSWrappedPropertyAndMethod : JSWrappedProperty
  23.     {
  24.         protected MethodInfo method;
  25.         private ParameterInfo[] parameters;
  26.        
  27.         internal JSWrappedPropertyAndMethod(PropertyInfo property, MethodInfo method, object obj) : base(property, obj)
  28.         {
  29.             this.method = method;
  30.             this.parameters = method.GetParameters();
  31.         }
  32.        
  33.         private object[] CheckArguments(object[] arguments)
  34.         {
  35.             if (arguments == null)
  36.                 return arguments;
  37.             int cArguments = arguments.Length;
  38.             int cParameters = this.parameters.Length;
  39.             if (cArguments >= cParameters)
  40.                 return arguments;
  41.             object[] newArgs = new object[cParameters];
  42.             ArrayObject.Copy(arguments, newArgs, cArguments);
  43.             for (int i = cArguments; i < cParameters; i++)
  44.                 newArgs[i] = System.Type.Missing;
  45.             return newArgs;
  46.         }
  47.        
  48.         internal object Invoke(object obj, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
  49.         {
  50.             parameters = CheckArguments(parameters);
  51.             if (this.obj != null && !(this.obj is Type))
  52.                 obj = this.obj;
  53.             return this.method.Invoke(obj, options, binder, parameters, culture);
  54.         }
  55.        
  56.         public MethodInfo Method {
  57.             get { return this.method; }
  58.         }
  59.     }
  60. }

Developer Fusion