示例#1
0
        public static IILGen Ld(this IILGen il, object?value)
        {
            switch (value)
            {
            case null:
                il.Ldnull();
                break;

            case bool b when !b:
                il.LdcI4(0);
                break;

            case bool b when b:
                il.LdcI4(1);
                break;

            case Int16 i16:
                il.LdcI4(i16);     // there is no instruction for 16b int
                break;

            case Int32 i32:
                il.LdcI4(i32);
                break;

            case Int64 i64:
                il.LdcI8(i64);
                break;

            case Single f:
                il.LdcR4(f);
                break;

            case Double d:
                il.LdcR8(d);
                break;

            case String s:
                il.Ldstr(s);
                break;

            default:
                throw new ArgumentException($"{value} is not supported.", nameof(value));
            }
            return(il);
        }