The Labs \ Source Viewer \ SSCLI \ System.Reflection.Emit \ SymbolMethod

  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 System.Reflection.Emit
  16. {
  17.     using System.Runtime.InteropServices;
  18.     using System;
  19.     using System.Reflection;
  20.     using CultureInfo = System.Globalization.CultureInfo;
  21.    
  22.     internal sealed class SymbolMethod : MethodInfo
  23.     {
  24.         #region Private Data Members
  25.         private ModuleBuilder m_module;
  26.         private Type m_containingType;
  27.         private string m_name;
  28.         private CallingConventions m_callingConvention;
  29.         private Type m_returnType;
  30.         private MethodToken m_mdMethod;
  31.         private int m_tkMethod;
  32.         private Type[] m_parameterTypes;
  33.         private SignatureHelper m_signature;
  34.         #endregion
  35.        
  36.         #region Constructor
  37.         internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
  38.         {
  39.             // This is a kind of MethodInfo to represent methods for array type of unbaked type
  40.            
  41.             // Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment
  42.             // this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing
  43.             // passed into it is this MethodToken. The MethodToken was forged using a TypeSpec for an Array type and
  44.             // the name of the method on Array.
  45.             // As none of the methods on Array have CustomModifiers their is no need to pass those around in here.
  46.             m_mdMethod = token;
  47.             m_tkMethod = token.Token;
  48.            
  49.             // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders.
  50.             m_returnType = returnType;
  51.             if (parameterTypes != null) {
  52.                 m_parameterTypes = new Type[parameterTypes.Length];
  53.                 Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length);
  54.             }
  55.             else {
  56.                 m_parameterTypes = new Type[0];
  57.             }
  58.            
  59.             m_module = mod;
  60.             m_containingType = arrayClass;
  61.             m_name = methodName;
  62.             m_callingConvention = callingConvention;
  63.            
  64.             m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, null, null, parameterTypes, null, null);
  65.         }
  66.         #endregion
  67.        
  68.         #region Internal Members
  69.         internal override Type[] GetParameterTypes()
  70.         {
  71.             return m_parameterTypes;
  72.         }
  73.        
  74.         internal MethodToken GetToken(ModuleBuilder mod)
  75.         {
  76.             return mod.GetArrayMethodToken(m_containingType, m_name, m_callingConvention, m_returnType, m_parameterTypes);
  77.         }
  78.        
  79.         #endregion
  80.        
  81.         #region MemberInfo Overrides
  82.         public override Module Module {
  83.             get { return m_module; }
  84.         }
  85.        
  86.         internal override int MetadataTokenInternal {
  87.             get { return m_tkMethod; }
  88.         }
  89.        
  90.         public override Type ReflectedType {
  91.             get { return m_containingType as Type; }
  92.         }
  93.        
  94.         public override string Name {
  95.             get { return m_name; }
  96.         }
  97.        
  98.         public override Type DeclaringType {
  99.             get { return m_containingType; }
  100.         }
  101.         #endregion
  102.        
  103.         #region MethodBase Overrides
  104.         public override ParameterInfo[] GetParameters()
  105.         {
  106.             throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  107.         }
  108.        
  109.         public override MethodImplAttributes GetMethodImplementationFlags()
  110.         {
  111.             throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  112.         }
  113.        
  114.         public override MethodAttributes Attributes {
  115.             get {
  116.                 throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  117.             }
  118.         }
  119.        
  120.         public override CallingConventions CallingConvention {
  121.             get { return m_callingConvention; }
  122.         }
  123.        
  124.         public override RuntimeMethodHandle MethodHandle {
  125.             get {
  126.                 throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  127.             }
  128.         }
  129.        
  130.         #endregion
  131.        
  132.         #region MethodInfo Overrides
  133.         internal override Type GetReturnType()
  134.         {
  135.             return m_returnType;
  136.         }
  137.        
  138.         public override ICustomAttributeProvider ReturnTypeCustomAttributes {
  139.             get { return null; }
  140.         }
  141.        
  142.         public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
  143.         {
  144.             throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  145.         }
  146.        
  147.         public override MethodInfo GetBaseDefinition()
  148.         {
  149.             return this;
  150.         }
  151.         #endregion
  152.        
  153.         #region ICustomAttributeProvider Implementation
  154.         public override object[] GetCustomAttributes(bool inherit)
  155.         {
  156.             throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  157.         }
  158.        
  159.         public override object[] GetCustomAttributes(Type attributeType, bool inherit)
  160.         {
  161.             throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  162.         }
  163.        
  164.         public override bool IsDefined(Type attributeType, bool inherit)
  165.         {
  166.             throw new NotSupportedException(Environment.GetResourceString("NotSupported_SymbolMethod"));
  167.         }
  168.        
  169.         #endregion
  170.        
  171.         #region Public Members
  172.         public Module GetModule()
  173.         {
  174.             return m_module;
  175.         }
  176.        
  177.         public MethodToken GetToken()
  178.         {
  179.             return m_mdMethod;
  180.         }
  181.        
  182.         #endregion
  183.     }
  184. }

Developer Fusion