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; }
73 PInvokeAttributes masked = (PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetNotSpec);
75 m_attributes |= masked;
77 m_attributes &= masked;
81 public bool IsCharSetAnsi {
82 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAnsi; }
84 PInvokeAttributes masked = (PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAnsi);
86 m_attributes |= masked;
88 m_attributes &= masked;
92 public bool IsCharSetUnicode {
93 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetUnicode; }
95 PInvokeAttributes masked = (PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetUnicode);
97 m_attributes |= masked;
99 m_attributes &= masked;
103 public bool IsCharSetAuto {
104 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAuto; }
106 PInvokeAttributes masked = (PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAuto);
108 m_attributes |= masked;
110 m_attributes &= masked;
114 public bool SupportsLastError {
115 get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.SupportsLastError; }
117 PInvokeAttributes masked = (PInvokeAttributes.CharSetMask & PInvokeAttributes.SupportsLastError);
119 m_attributes |= masked;
121 m_attributes &= masked;
125 public bool IsCallConvWinapi {
126 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvWinapi; }
128 PInvokeAttributes masked = (PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvWinapi);
130 m_attributes |= masked;
132 m_attributes &= masked;
136 public bool IsCallConvCdecl {
137 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvCdecl; }
139 PInvokeAttributes masked = (PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvCdecl);
141 m_attributes |= masked;
143 m_attributes &= masked;
147 public bool IsCallConvStdCall {
148 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvStdCall; }
150 PInvokeAttributes masked = (PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvStdCall);
152 m_attributes |= masked;
154 m_attributes &= masked;
158 public bool IsCallConvThiscall {
159 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvThiscall; }
161 PInvokeAttributes masked = (PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvThiscall);
163 m_attributes |= masked;
165 m_attributes &= masked;
169 public bool IsCallConvFastcall {
170 get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvFastcall; }
172 PInvokeAttributes masked = (PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvFastcall);
174 m_attributes |= masked;
176 m_attributes &= masked;
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);