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

  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. /*============================================================
  16. **
  17. ** Class:  ParameterBuilder
  18. **
  19. **
  20. ** ParameterBuilder is used to create/associate parameter information
  21. **
  22. **
  23. ===========================================================*/
  24. namespace System.Reflection.Emit
  25. {
  26.     using System.Runtime.InteropServices;
  27.     using System;
  28.     using System.Reflection;
  29.     using System.Security.Permissions;
  30.    
  31.     [ClassInterface(ClassInterfaceType.None)]
  32.     [ComDefaultInterface(typeof(_ParameterBuilder))]
  33.     [System.Runtime.InteropServices.ComVisible(true)]
  34.     public class ParameterBuilder : _ParameterBuilder
  35.     {
  36.         // set ParamMarshal
  37.         [Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202")]
  38.         public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
  39.         {
  40.             if (unmanagedMarshal == null) {
  41.                 throw new ArgumentNullException("unmanagedMarshal");
  42.             }
  43.            
  44.             byte[] ubMarshal = unmanagedMarshal.InternalGetBytes();
  45.             TypeBuilder.InternalSetMarshalInfo(m_methodBuilder.GetModule(), m_pdToken.Token, ubMarshal, ubMarshal.Length);
  46.         }
  47.        
  48.         // Set the default value of the parameter
  49.         public virtual void SetConstant(object defaultValue)
  50.         {
  51.             TypeBuilder.SetConstantValue(m_methodBuilder.GetModule(), m_pdToken.Token, m_iPosition == 0 ? m_methodBuilder.m_returnType : m_methodBuilder.m_parameterTypes[m_iPosition - 1], defaultValue);
  52.         }
  53.        
  54.         // Use this function if client decides to form the custom attribute blob themselves
  55.         [System.Runtime.InteropServices.ComVisible(true)]
  56.         public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
  57.         {
  58.             if (con == null)
  59.                 throw new ArgumentNullException("con");
  60.             if (binaryAttribute == null)
  61.                 throw new ArgumentNullException("binaryAttribute");
  62.            
  63.             TypeBuilder.InternalCreateCustomAttribute(m_pdToken.Token, ((ModuleBuilder)m_methodBuilder.GetModule()).GetConstructorToken(con).Token, binaryAttribute, m_methodBuilder.GetModule(), false);
  64.         }
  65.        
  66.         // Use this function if client wishes to build CustomAttribute using CustomAttributeBuilder
  67.         public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
  68.         {
  69.             if (customBuilder == null) {
  70.                 throw new ArgumentNullException("customBuilder");
  71.             }
  72.             customBuilder.CreateCustomAttribute((ModuleBuilder)(m_methodBuilder.GetModule()), m_pdToken.Token);
  73.         }
  74.        
  75.         //*******************************
  76.         // Make a private constructor so these cannot be constructed externally.
  77.         //*******************************
  78.         private ParameterBuilder()
  79.         {
  80.         }
  81.        
  82.        
  83.         // can be NULL string
  84.         internal ParameterBuilder(MethodBuilder methodBuilder, int sequence, ParameterAttributes attributes, string strParamName)
  85.         {
  86.             m_iPosition = sequence;
  87.             m_strParamName = strParamName;
  88.             m_methodBuilder = methodBuilder;
  89.             m_strParamName = strParamName;
  90.             m_attributes = attributes;
  91.             m_pdToken = new ParameterToken(TypeBuilder.InternalSetParamInfo(m_methodBuilder.GetModule(), m_methodBuilder.GetToken().Token, sequence, attributes, strParamName));
  92.         }
  93.        
  94.         public virtual ParameterToken GetToken()
  95.         {
  96.             return m_pdToken;
  97.         }
  98.        
  99.         void _ParameterBuilder.GetTypeInfoCount(out uint pcTInfo)
  100.         {
  101.             throw new NotImplementedException();
  102.         }
  103.        
  104.         void _ParameterBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
  105.         {
  106.             throw new NotImplementedException();
  107.         }
  108.        
  109.         void _ParameterBuilder.GetIDsOfNames(        [In()]
  110. ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  111.         {
  112.             throw new NotImplementedException();
  113.         }
  114.        
  115.         void _ParameterBuilder.Invoke(uint dispIdMember,         [In()]
  116. ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  117.         {
  118.             throw new NotImplementedException();
  119.         }
  120.        
  121.         internal virtual int MetadataTokenInternal {
  122.             get { return m_pdToken.Token; }
  123.         }
  124.        
  125.         public virtual string Name {
  126.             get { return m_strParamName; }
  127.         }
  128.        
  129.         public virtual int Position {
  130.             get { return m_iPosition; }
  131.         }
  132.        
  133.         public virtual int Attributes {
  134.             get { return (int)m_attributes; }
  135.         }
  136.        
  137.         public bool IsIn {
  138.             get { return ((m_attributes & ParameterAttributes.In) != 0); }
  139.         }
  140.         public bool IsOut {
  141.             get { return ((m_attributes & ParameterAttributes.Out) != 0); }
  142.         }
  143.         public bool IsOptional {
  144.             get { return ((m_attributes & ParameterAttributes.Optional) != 0); }
  145.         }
  146.        
  147.         private string m_strParamName;
  148.         private int m_iPosition;
  149.         private ParameterAttributes m_attributes;
  150.         private MethodBuilder m_methodBuilder;
  151.         private ParameterToken m_pdToken;
  152.     }
  153. }

Developer Fusion