Пример #1
0
        // Emit the load of a constant field.  We can't emit a ldsfld/ldfld of a constant so we have to get its value
        // and then emit a ldc.
		private static void EmitLiteral(System.Reflection.FieldInfo fi, FleeILGenerator ilg, IServiceProvider services)
		{
			object value = fi.GetValue(null);
			Type t = value.GetType();
			TypeCode code = Type.GetTypeCode(t);
			LiteralElement elem = null;

			switch (code) {
				case TypeCode.Char:
				case TypeCode.Byte:
				case TypeCode.SByte:
				case TypeCode.Int16:
				case TypeCode.UInt16:
				case TypeCode.Int32:
					elem = new Int32LiteralElement(System.Convert.ToInt32(value));
					break;
				case TypeCode.UInt32:
					elem = new UInt32LiteralElement((UInt32)value);
					break;
				case TypeCode.Int64:
					elem = new Int64LiteralElement((Int64)value);
					break;
				case TypeCode.UInt64:
					elem = new UInt64LiteralElement((UInt64)value);
					break;
				case TypeCode.Double:
					elem = new DoubleLiteralElement((double)value);
					break;
				case TypeCode.Single:
					elem = new SingleLiteralElement((float)value);
					break;
				case TypeCode.Boolean:
					elem = new BooleanLiteralElement((bool)value);
					break;
				case TypeCode.String:
					elem = new StringLiteralElement((string)value);
					break;
				default:
					elem = null;
					Debug.Fail("Unsupported constant type");
					break;
			}

			elem.Emit(ilg, services);
		}
Пример #2
0
        private static void EmitStringEquality(FleeILGenerator ilg, LogicalCompareOperation op, IServiceProvider services)
        {
            // Get the StringComparison from the options
            var options = (ExpressionOptions)services.GetService(typeof(ExpressionOptions));
            var ic = new Int32LiteralElement((int)options.StringComparison);

            ic.Emit(ilg, services);

            // and emit the method call
            var mi = typeof(string).GetMethod("Equals", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, new Type[] {
                typeof(string),
                typeof(string),
                typeof(StringComparison)
            }, null);
            ilg.Emit(OpCodes.Call, mi);

            if (op == LogicalCompareOperation.NotEqual) {
                ilg.Emit(OpCodes.Ldc_I4_0);
                ilg.Emit(OpCodes.Ceq);
            }
        }