Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy / Generators / Emitters / SimpleAST / IndirectReference.cs
blobe12975e7ceb6ee3df51085337e735d895e172561
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
17 using System;
18 using System.Reflection.Emit;
20 /// <summary>
21 /// Wraps a reference that is passed
22 /// ByRef and provides indirect load/store support.
23 /// </summary>
24 public class IndirectReference : TypeReference
26 public IndirectReference(TypeReference byRefReference) :
27 base(byRefReference, byRefReference.Type.GetElementType())
29 if (!byRefReference.Type.IsByRef)
31 throw new ArgumentException("Expected an IsByRef reference", "byRefReference");
35 // TODO: Better name
36 public static TypeReference WrapIfByRef(TypeReference reference)
38 return reference.Type.IsByRef ? new IndirectReference(reference) : reference;
41 // TODO: Better name
42 public static TypeReference[] WrapIfByRef(TypeReference[] references)
44 TypeReference[] result = new TypeReference[references.Length];
46 for(int i = 0; i < references.Length; i++)
48 result[i] = WrapIfByRef(references[i]);
51 return result;
54 public override void LoadReference(ILGenerator gen)
56 OpCodeUtil.EmitLoadIndirectOpCodeForType(gen, Type);
59 public override void StoreReference(ILGenerator gen)
61 OpCodeUtil.EmitStoreIndirectOpCodeForType(gen, Type);
64 public override void LoadAddressOfReference(ILGenerator gen)
66 // Load of owner reference takes care of this.