Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Builder / CodeBuilder / Utils / OpCodesDictionary.cs
blob1c6526f7f7d9589a37eff4fc4e90ac40b8a25ac4
1 // Copyright 2004-2007 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.Builder.CodeBuilder.Utils
17 using System;
18 using System.Collections;
19 using System.Reflection.Emit;
21 /// <summary>
22 /// Provides appropriate Ldc.X opcode for the type of primitive value to be loaded.
23 /// </summary>
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;
45 public OpCode this[Type type]
47 get
49 if (Dictionary.Contains(type))
51 return (OpCode) Dictionary[ type ];
53 return EmptyOpCode;
57 public static LdcOpCodesDictionary Instance
59 get { return _dict; }
62 public static OpCode EmptyOpCode
64 get { return _emptyOpCode; }
68 /// <summary>
69 /// Provides appropriate Ldind.X opcode for
70 /// the type of primitive value to be loaded indirectly.
71 /// </summary>
72 public sealed class LdindOpCodesDictionary : DictionaryBase
74 private static readonly LdindOpCodesDictionary _dict = new LdindOpCodesDictionary();
76 private static readonly OpCode _emptyOpCode = new OpCode();
78 private LdindOpCodesDictionary() : base()
80 Dictionary[ typeof (bool) ] = OpCodes.Ldind_I1;
81 Dictionary[ typeof (char) ] = OpCodes.Ldind_I2;
82 Dictionary[ typeof (SByte) ] = OpCodes.Ldind_I1;
83 Dictionary[ typeof (Int16) ] = OpCodes.Ldind_I2;
84 Dictionary[ typeof (Int32) ] = OpCodes.Ldind_I4;
85 Dictionary[ typeof (Int64) ] = OpCodes.Ldind_I8;
86 Dictionary[ typeof (float) ] = OpCodes.Ldind_R4;
87 Dictionary[ typeof (double) ] = OpCodes.Ldind_R8;
88 Dictionary[ typeof (byte) ] = OpCodes.Ldind_U1;
89 Dictionary[ typeof (UInt16) ] = OpCodes.Ldind_U2;
90 Dictionary[ typeof (UInt32) ] = OpCodes.Ldind_U4;
93 public OpCode this[Type type]
95 get
97 if (Dictionary.Contains(type))
99 return (OpCode) Dictionary[ type ];
101 return EmptyOpCode;
105 public static LdindOpCodesDictionary Instance
107 get { return _dict; }
110 public static OpCode EmptyOpCode
112 get { return _emptyOpCode; }
116 /// <summary>
117 /// Provides appropriate Stind.X opcode
118 /// for the type of primitive value to be stored indirectly.
119 /// </summary>
120 public sealed class StindOpCodesDictionary : DictionaryBase
122 private static readonly StindOpCodesDictionary _dict = new StindOpCodesDictionary();
124 private static readonly OpCode _emptyOpCode = new OpCode();
126 private StindOpCodesDictionary() : base()
128 Dictionary[typeof(bool)] = OpCodes.Stind_I1;
129 Dictionary[typeof(char)] = OpCodes.Stind_I2;
130 Dictionary[typeof(SByte)] = OpCodes.Stind_I1;
131 Dictionary[typeof(Int16)] = OpCodes.Stind_I2;
132 Dictionary[typeof(Int32)] = OpCodes.Stind_I4;
133 Dictionary[typeof(Int64)] = OpCodes.Stind_I8;
134 Dictionary[typeof(float)] = OpCodes.Stind_R4;
135 Dictionary[typeof(double)] = OpCodes.Stind_R8;
136 Dictionary[typeof(byte)] = OpCodes.Stind_I1;
137 Dictionary[typeof(UInt16)] = OpCodes.Stind_I2;
138 Dictionary[typeof(UInt32)] = OpCodes.Stind_I4;
141 public OpCode this[Type type]
145 if (Dictionary.Contains(type))
147 return (OpCode)Dictionary[type];
149 return EmptyOpCode;
153 public static StindOpCodesDictionary Instance
155 get { return _dict; }
158 public static OpCode EmptyOpCode
160 get { return _emptyOpCode; }