예제 #1
0
        private static Func <ILGenerator, ILGenerator> LookUpForClass2String(Type source, Type destination)
        {
            if (source.IsValueType)
            {
                return(null);
            }
            if (typeof(String) != destination)
            {
                return(null);
            }

            // instance or null is on top of the stack
            return(il => il
                   .dup()
                   .@if(true, x => x
                        .callvirt(FromLambda.Method <Object, String>(o => o.ToString()))
                        ));
        }
예제 #2
0
        private static Func <ILGenerator, ILGenerator> LookUpForEnum2String(Type source, Type destination)
        {
            if (!source.IsEnum)
            {
                return(null);
            }
            if (typeof(String) != destination)
            {
                return(null);
            }

            // unboxed enum is on top of the stack
            return(il => il
                   .box(source)
                   .ldstr("d")
                   .call(FromLambda.Method <Enum, String, String>((e, f) => e.ToString(f)))
                   );
        }
예제 #3
0
        private static Func <ILGenerator, ILGenerator> LookUpForStruct2String(Type source, Type destination)
        {
            if (!source.IsValueType)
            {
                return(null);
            }
            if (typeof(String) != destination)
            {
                return(null);
            }

            LocalBuilder value;

            // struct is on top of the stack
            return(il => il
                   .DefineLocal(source, out value)
                   .stloc(value)
                   .ldloca(value)
                   .constrained(source)
                   .callvirt(FromLambda.Method <Object, String>(o => o.ToString()))
                   );
        }