From: stephentoub Date: Wed, 10 Jun 2015 13:24:43 +0000 (-0400) Subject: Implement ILGenerator on Unix to use System.Console.dll X-Git-Tag: accepted/tizen/base/20180629.140029~6615^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1ac4e76e3f0a5dea311a0642d2abaac3acea43fc;p=platform%2Fupstream%2Fcoreclr.git Implement ILGenerator on Unix to use System.Console.dll The System.Console type in mscorlib on Unix is internal and lacks any ability to write out. As such, System.Reflection.Emit.ILGenerator.EmitWriteLine needs to use the System.Console from System.Console.dll. --- diff --git a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs index 4c44eb0..fa6d539 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs @@ -1174,6 +1174,17 @@ namespace System.Reflection.Emit 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. @@ -1181,7 +1192,7 @@ namespace System.Reflection.Emit 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); } @@ -1198,7 +1209,7 @@ namespace System.Reflection.Emit 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]; @@ -1230,7 +1241,7 @@ namespace System.Reflection.Emit } 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) {