this.Emit(OpCodes.Throw);
}
+ private static Type GetConsoleType()
+ {
+#if FEATURE_LEGACYSURFACE
+ return typeof(Console);
+#else
+ return Type.GetType(
+ "System.Console, System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=" + AssemblyRef.MicrosoftPublicKeyToken,
+ throwOnError: true);
+#endif
+ }
+
public virtual void EmitWriteLine(String value)
{
// Emits the IL to call Console.WriteLine with a string.
Emit(OpCodes.Ldstr, value);
Type[] parameterTypes = new Type[1];
parameterTypes[0] = typeof(String);
- MethodInfo mi = typeof(Console).GetMethod("WriteLine", parameterTypes);
+ MethodInfo mi = GetConsoleType().GetMethod("WriteLine", parameterTypes);
Emit(OpCodes.Call, mi);
}
throw new ArgumentException(Environment.GetResourceString("InvalidOperation_BadILGeneratorUsage"));
}
- MethodInfo prop = typeof(Console).GetMethod("get_Out");
+ MethodInfo prop = GetConsoleType().GetMethod("get_Out");
Emit(OpCodes.Call, prop);
Emit(OpCodes.Ldloc, localBuilder);
Type[] parameterTypes = new Type[1];
}
Contract.EndContractBlock();
- MethodInfo prop = typeof(Console).GetMethod("get_Out");
+ MethodInfo prop = GetConsoleType().GetMethod("get_Out");
Emit(OpCodes.Call, prop);
if ((fld.Attributes & FieldAttributes.Static)!=0) {