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())) )); }
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))) ); }
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())) ); }