1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Reflection
.Emit
;
21 /// Wraps a reference that is passed
22 /// ByRef and provides indirect load/store support.
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");
36 public static TypeReference
WrapIfByRef(TypeReference reference
)
38 return reference
.Type
.IsByRef
? new IndirectReference(reference
) : reference
;
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
]);
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.