mscorlib(4.0.0.0) API with additions
ParameterBuilder.cs
2 using System.Security;
3 
5 {
7  [ClassInterface(ClassInterfaceType.None)]
8  [ComDefaultInterface(typeof(_ParameterBuilder))]
9  [ComVisible(true)]
11  {
12  private string m_strParamName;
13 
14  private int m_iPosition;
15 
16  private ParameterAttributes m_attributes;
17 
18  private MethodBuilder m_methodBuilder;
19 
20  private ParameterToken m_pdToken;
21 
22  internal int MetadataTokenInternal => m_pdToken.Token;
23 
26  public virtual string Name => m_strParamName;
27 
30  public virtual int Position => m_iPosition;
31 
34  public virtual int Attributes => (int)m_attributes;
35 
38  public bool IsIn => (m_attributes & ParameterAttributes.In) != ParameterAttributes.None;
39 
42  public bool IsOut => (m_attributes & ParameterAttributes.Out) != ParameterAttributes.None;
43 
46  public bool IsOptional => (m_attributes & ParameterAttributes.Optional) != ParameterAttributes.None;
47 
52  [SecuritySafeCritical]
53  [Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202")]
54  public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
55  {
56  if (unmanagedMarshal == null)
57  {
58  throw new ArgumentNullException("unmanagedMarshal");
59  }
60  byte[] array = unmanagedMarshal.InternalGetBytes();
61  TypeBuilder.SetFieldMarshal(m_methodBuilder.GetModuleBuilder().GetNativeHandle(), m_pdToken.Token, array, array.Length);
62  }
63 
67  [SecuritySafeCritical]
68  public virtual void SetConstant(object defaultValue)
69  {
70  TypeBuilder.SetConstantValue(m_methodBuilder.GetModuleBuilder(), m_pdToken.Token, (m_iPosition == 0) ? m_methodBuilder.ReturnType : m_methodBuilder.m_parameterTypes[m_iPosition - 1], defaultValue);
71  }
72 
78  [SecuritySafeCritical]
79  [ComVisible(true)]
80  public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
81  {
82  if (con == null)
83  {
84  throw new ArgumentNullException("con");
85  }
86  if (binaryAttribute == null)
87  {
88  throw new ArgumentNullException("binaryAttribute");
89  }
90  TypeBuilder.DefineCustomAttribute(m_methodBuilder.GetModuleBuilder(), m_pdToken.Token, ((ModuleBuilder)m_methodBuilder.GetModule()).GetConstructorToken(con).Token, binaryAttribute, toDisk: false, updateCompilerFlags: false);
91  }
92 
97  [SecuritySafeCritical]
98  public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
99  {
100  if (customBuilder == null)
101  {
102  throw new ArgumentNullException("customBuilder");
103  }
104  customBuilder.CreateCustomAttribute((ModuleBuilder)m_methodBuilder.GetModule(), m_pdToken.Token);
105  }
106 
107  private ParameterBuilder()
108  {
109  }
110 
111  [SecurityCritical]
112  internal ParameterBuilder(MethodBuilder methodBuilder, int sequence, ParameterAttributes attributes, string strParamName)
113  {
114  m_iPosition = sequence;
115  m_strParamName = strParamName;
116  m_methodBuilder = methodBuilder;
117  m_strParamName = strParamName;
118  m_attributes = attributes;
119  m_pdToken = new ParameterToken(TypeBuilder.SetParamInfo(m_methodBuilder.GetModuleBuilder().GetNativeHandle(), m_methodBuilder.GetToken().Token, sequence, attributes, strParamName));
120  }
121 
124  public virtual ParameterToken GetToken()
125  {
126  return m_pdToken;
127  }
128 
132  void _ParameterBuilder.GetTypeInfoCount(out uint pcTInfo)
133  {
134  throw new NotImplementedException();
135  }
136 
142  void _ParameterBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
143  {
144  throw new NotImplementedException();
145  }
146 
154  void _ParameterBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
155  {
156  throw new NotImplementedException();
157  }
158 
169  void _ParameterBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
170  {
171  throw new NotImplementedException();
172  }
173  }
174 }
Module GetModule()
Returns a reference to the module that contains this method.
bool IsOptional
Retrieves whether this parameter is optional.
virtual int Position
Retrieves the signature position for this parameter.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
Set a custom attribute using a specified custom attribute blob.
int Token
Retrieves the metadata token for this parameter.
MethodToken GetToken()
Returns the MethodToken that represents the token for this method.
Discovers the attributes of a class constructor and provides access to constructor metadata.
Definition: __Canon.cs:3
virtual int Attributes
Retrieves the attributes for this parameter.
virtual string Name
Retrieves the name of this parameter.
Exposes the T:System.Reflection.Emit.ParameterBuilder class to unmanaged code.
Creates or associates parameter information.
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
Defines and creates new instances of classes during run time.
Definition: TypeBuilder.cs:15
bool IsOut
Retrieves whether this parameter is an output parameter.
Defines and represents a module in a dynamic assembly.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
virtual void SetConstant(object defaultValue)
Sets the default value of the parameter.
ParameterAttributes
Defines the attributes that can be associated with a parameter. These are defined in CorHdr....
override Type ReturnType
Gets the return type of the method represented by this T:System.Reflection.Emit.MethodBuilder.
Defines and represents a method (or constructor) on a dynamic class.
Represents the class that describes how to marshal a field from managed to unmanaged code....
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
bool IsIn
Retrieves whether this is an input parameter.
int Token
Returns the metadata token for this method.
Definition: MethodToken.cs:17
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
virtual ParameterToken GetToken()
Retrieves the token for this parameter.
The ParameterToken struct is an opaque representation of the token returned by the metadata to repres...
virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
Specifies the marshaling for this parameter.
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
The exception that is thrown when a requested method or operation is not implemented.
void SetCustomAttribute(CustomAttributeBuilder customBuilder)
Set a custom attribute using a custom attribute builder.