1 // Copyright 2004-2007 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
18 using System
.Collections
;
19 using System
.Reflection
.Emit
;
22 /// Provides appropriate Ldc.X opcode for the type of primitive value to be loaded.
24 public sealed class LdcOpCodesDictionary
: DictionaryBase
26 private static readonly LdcOpCodesDictionary _dict
= new LdcOpCodesDictionary();
28 private static readonly OpCode _emptyOpCode
= new OpCode();
30 private LdcOpCodesDictionary() : base()
32 Dictionary
[typeof(bool)] = OpCodes
.Ldc_I4
;
33 Dictionary
[typeof(char)] = OpCodes
.Ldc_I4
;
34 Dictionary
[typeof(SByte
)] = OpCodes
.Ldc_I4
;
35 Dictionary
[typeof(Int16
)] = OpCodes
.Ldc_I4
;
36 Dictionary
[typeof(Int32
)] = OpCodes
.Ldc_I4
;
37 Dictionary
[typeof(Int64
)] = OpCodes
.Ldc_I8
;
38 Dictionary
[typeof(float)] = OpCodes
.Ldc_R4
;
39 Dictionary
[typeof(double)] = OpCodes
.Ldc_R8
;
40 Dictionary
[typeof(byte)] = OpCodes
.Ldc_I4_0
;
41 Dictionary
[typeof(UInt16
)] = OpCodes
.Ldc_I4_0
;
42 Dictionary
[typeof(UInt32
)] = OpCodes
.Ldc_I4_0
;
43 Dictionary
[typeof(UInt64
)] = OpCodes
.Ldc_I4_0
;
46 public OpCode
this[Type type
]
50 if (Dictionary
.Contains(type
))
52 return (OpCode
) Dictionary
[type
];
58 public static LdcOpCodesDictionary Instance
63 public static OpCode EmptyOpCode
65 get { return _emptyOpCode; }