| 1 |
// |
| 2 |
// MarshalDesc.cs |
| 3 |
// |
| 4 |
// Author: |
| 5 |
// Jb Evain ([email protected]) |
| 6 |
// |
| 7 |
// (C) 2005 Jb Evain |
| 8 |
// |
| 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: |
| 16 |
// |
| 17 |
// The above copyright notice and this permission notice shall be |
| 18 |
// included in all copies or substantial portions of the Software. |
| 19 |
// |
| 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. |
| 27 |
// |
| 28 |
|
| 29 |
namespace Mono.Cecil { |
| 30 |
|
| 31 |
using System; |
| 32 |
|
| 33 |
internal class MarshalSpec { |
| 34 |
|
| 35 |
NativeType m_natIntr; |
| 36 |
IHasMarshalSpec m_container; |
| 37 |
|
| 38 |
public NativeType NativeIntrinsic { |
| 39 |
get { return m_natIntr; } |
| 40 |
set { m_natIntr = value; } |
| 41 |
} |
| 42 |
|
| 43 |
public IHasMarshalSpec Container { |
| 44 |
get { return m_container; } |
| 45 |
set { m_container = value; } |
| 46 |
} |
| 47 |
|
| 48 |
public MarshalSpec (NativeType natIntr, IHasMarshalSpec container) |
| 49 |
{ |
| 50 |
m_natIntr = natIntr; |
| 51 |
m_container = container; |
| 52 |
} |
| 53 |
|
| 54 |
public virtual void Accept (IReflectionVisitor visitor) |
| 55 |
{ |
| 56 |
visitor.VisitMarshalSpec (this); |
| 57 |
} |
| 58 |
|
| 59 |
public virtual MarshalSpec CloneInto (IHasMarshalSpec container) |
| 60 |
{ |
| 61 |
return new MarshalSpec (m_natIntr, container); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
internal sealed class ArrayMarshalSpec : MarshalSpec { |
| 66 |
|
| 67 |
NativeType m_elemType; |
| 68 |
int m_paramNum; |
| 69 |
int m_elemMult; |
| 70 |
int m_numElem; |
| 71 |
|
| 72 |
public NativeType ElemType { |
| 73 |
get { return m_elemType; } |
| 74 |
set { m_elemType = value; } |
| 75 |
} |
| 76 |
|
| 77 |
public int ParamNum { |
| 78 |
get { return m_paramNum; } |
| 79 |
set { m_paramNum = value; } |
| 80 |
} |
| 81 |
|
| 82 |
public int ElemMult { |
| 83 |
get { return m_elemMult; } |
| 84 |
set { m_elemMult = value; } |
| 85 |
} |
| 86 |
|
| 87 |
public int NumElem { |
| 88 |
get { return m_numElem; } |
| 89 |
set { m_numElem = value; } |
| 90 |
} |
| 91 |
|
| 92 |
public ArrayMarshalSpec (IHasMarshalSpec container) : base (NativeType.ARRAY, container) |
| 93 |
{ |
| 94 |
} |
| 95 |
|
| 96 |
public override MarshalSpec CloneInto (IHasMarshalSpec container) |
| 97 |
{ |
| 98 |
ArrayMarshalSpec spec = new ArrayMarshalSpec (container); |
| 99 |
spec.m_elemType = m_elemType; |
| 100 |
spec.m_paramNum = m_paramNum; |
| 101 |
spec.m_elemMult = m_elemMult; |
| 102 |
spec.m_numElem = m_numElem; |
| 103 |
return spec; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
internal sealed class CustomMarshalerSpec : MarshalSpec { |
| 108 |
|
| 109 |
Guid m_guid; |
| 110 |
string m_unmanagedType; |
| 111 |
string m_managedType; |
| 112 |
string m_cookie; |
| 113 |
|
| 114 |
public Guid Guid { |
| 115 |
get { return m_guid; } |
| 116 |
set { m_guid = value; } |
| 117 |
} |
| 118 |
|
| 119 |
public String UnmanagedType { |
| 120 |
get { return m_unmanagedType; } |
| 121 |
set { m_unmanagedType = value; } |
| 122 |
} |
| 123 |
|
| 124 |
public string ManagedType { |
| 125 |
get { return m_managedType; } |
| 126 |
set { m_managedType = value; } |
| 127 |
} |
| 128 |
|
| 129 |
public string Cookie { |
| 130 |
get { return m_cookie; } |
| 131 |
set { m_cookie = value; } |
| 132 |
} |
| 133 |
|
| 134 |
public CustomMarshalerSpec (IHasMarshalSpec container) : base (NativeType.CUSTOMMARSHALER, container) |
| 135 |
{ |
| 136 |
} |
| 137 |
|
| 138 |
public override MarshalSpec CloneInto (IHasMarshalSpec container) |
| 139 |
{ |
| 140 |
CustomMarshalerSpec spec = new CustomMarshalerSpec (container); |
| 141 |
spec.m_guid = m_guid; |
| 142 |
spec.m_unmanagedType = m_unmanagedType; |
| 143 |
spec.m_managedType = m_managedType; |
| 144 |
spec.m_cookie = m_cookie; |
| 145 |
return spec; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
internal sealed class SafeArraySpec : MarshalSpec { |
| 150 |
|
| 151 |
private VariantType m_elemType; |
| 152 |
|
| 153 |
public VariantType ElemType { |
| 154 |
get { return m_elemType; } |
| 155 |
set { m_elemType = value; } |
| 156 |
} |
| 157 |
|
| 158 |
public SafeArraySpec (IHasMarshalSpec container) : base (NativeType.SAFEARRAY, container) |
| 159 |
{ |
| 160 |
} |
| 161 |
|
| 162 |
public override MarshalSpec CloneInto(IHasMarshalSpec container) |
| 163 |
{ |
| 164 |
SafeArraySpec spec = new SafeArraySpec (container); |
| 165 |
spec.m_elemType = m_elemType; |
| 166 |
return spec; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
internal sealed class FixedArraySpec : MarshalSpec { |
| 171 |
|
| 172 |
private int m_numElem; |
| 173 |
private NativeType m_elemType; |
| 174 |
|
| 175 |
public int NumElem { |
| 176 |
get { return m_numElem; } |
| 177 |
set { m_numElem = value; } |
| 178 |
} |
| 179 |
|
| 180 |
public NativeType ElemType { |
| 181 |
get { return m_elemType; } |
| 182 |
set { m_elemType = value; } |
| 183 |
} |
| 184 |
|
| 185 |
public FixedArraySpec (IHasMarshalSpec container) : base (NativeType.FIXEDARRAY, container) |
| 186 |
{ |
| 187 |
} |
| 188 |
|
| 189 |
public override MarshalSpec CloneInto (IHasMarshalSpec container) |
| 190 |
{ |
| 191 |
FixedArraySpec spec = new FixedArraySpec (container); |
| 192 |
spec.m_numElem = m_numElem; |
| 193 |
spec.m_elemType = m_elemType; |
| 194 |
return spec; |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
internal sealed class FixedSysStringSpec : MarshalSpec { |
| 199 |
|
| 200 |
private int m_size; |
| 201 |
|
| 202 |
public int Size { |
| 203 |
get { return m_size; } |
| 204 |
set { m_size = value; } |
| 205 |
} |
| 206 |
|
| 207 |
public FixedSysStringSpec (IHasMarshalSpec container) : base (NativeType.FIXEDSYSSTRING, container) |
| 208 |
{ |
| 209 |
} |
| 210 |
|
| 211 |
public override MarshalSpec CloneInto (IHasMarshalSpec container) |
| 212 |
{ |
| 213 |
FixedSysStringSpec spec = new FixedSysStringSpec (container); |
| 214 |
spec.m_size = m_size; |
| 215 |
return spec; |
| 216 |
} |
| 217 |
} |
| 218 |
} |