5 // Jb Evain (jbevain@gmail.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 namespace Mono.Cecil {
31 public sealed class PInvokeInfo : IReflectionVisitable {
33 MethodDefinition m_meth;
35 PInvokeAttributes m_attributes;
37 ModuleReference m_module;
39 public MethodDefinition Method {
40 get { return m_meth; }
43 public PInvokeAttributes Attributes {
44 get { return m_attributes; }
45 set { m_attributes = value; }
48 public string EntryPoint {
49 get { return m_entryPoint; }
50 set { m_entryPoint = value; }
53 public ModuleReference Module {
54 get { return m_module; }
55 set { m_module = value; }
58 #region PInvokeAttributes
60 public bool IsNoMangle {
61 get { return (m_attributes & PInvokeAttributes.NoMangle) != 0; }
64 m_attributes |= PInvokeAttributes.NoMangle;
66 m_attributes &= ~PInvokeAttributes.NoMangle;
70 public bool IsCharSetNotSpec {
71 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetNotSpec; }
74 m_attributes &= ~PInvokeAttributes.CharSetMask;
75 m_attributes |= PInvokeAttributes.CharSetNotSpec;
77 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetNotSpec);
81 public bool IsCharSetAnsi {
82 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAnsi; }
85 m_attributes &= ~PInvokeAttributes.CharSetMask;
86 m_attributes |= PInvokeAttributes.CharSetAnsi;
88 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAnsi);
92 public bool IsCharSetUnicode {
93 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetUnicode; }
96 m_attributes &= ~PInvokeAttributes.CharSetMask;
97 m_attributes |= PInvokeAttributes.CharSetUnicode;
99 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetUnicode);
103 public bool IsCharSetAuto {
104 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAuto; }
107 m_attributes &= ~PInvokeAttributes.CharSetMask;
108 m_attributes |= PInvokeAttributes.CharSetAuto;
110 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAuto);
114 public bool SupportsLastError {
115 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.SupportsLastError; }
118 m_attributes &= ~PInvokeAttributes.CharSetMask;
119 m_attributes |= PInvokeAttributes.SupportsLastError;
121 m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.SupportsLastError);
125 public bool IsCallConvWinapi {
126 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvWinapi; }
129 m_attributes &= ~PInvokeAttributes.CallConvMask;
130 m_attributes |= PInvokeAttributes.CallConvWinapi;
132 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvWinapi);
136 public bool IsCallConvCdecl {
137 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvCdecl; }
140 m_attributes &= ~PInvokeAttributes.CallConvMask;
141 m_attributes |= PInvokeAttributes.CallConvCdecl;
143 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvCdecl);
147 public bool IsCallConvStdCall {
148 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvStdCall; }
151 m_attributes &= ~PInvokeAttributes.CallConvMask;
152 m_attributes |= PInvokeAttributes.CallConvStdCall;
154 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvStdCall);
158 public bool IsCallConvThiscall {
159 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvThiscall; }
162 m_attributes &= ~PInvokeAttributes.CallConvMask;
163 m_attributes |= PInvokeAttributes.CallConvThiscall;
165 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvThiscall);
169 public bool IsCallConvFastcall {
170 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvFastcall; }
173 m_attributes &= ~PInvokeAttributes.CallConvMask;
174 m_attributes |= PInvokeAttributes.CallConvFastcall;
176 m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvFastcall);
182 public PInvokeInfo (MethodDefinition meth)
187 public PInvokeInfo (MethodDefinition meth, PInvokeAttributes attrs,
188 string entryPoint, ModuleReference mod) : this (meth)
190 m_attributes = attrs;
191 m_entryPoint = entryPoint;
195 public void Accept (IReflectionVisitor visitor)
197 visitor.VisitPInvokeInfo (this);