From ebf2906280b18e386f332296873e8f76372d41b0 Mon Sep 17 00:00:00 2001 From: Vitek Karas Date: Tue, 25 Feb 2020 16:51:09 -0800 Subject: [PATCH] Trivial cleanup in ILGenerator.WriteLine (#32794) Avoids unnecessary cast. --- .../src/System/Reflection/Emit/ILGenerator.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs index fd76cf3..93c517f 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs @@ -1102,12 +1102,12 @@ namespace System.Reflection.Emit Emit(OpCodes.Call, prop); Emit(OpCodes.Ldloc, localBuilder); Type[] parameterTypes = new Type[1]; - object cls = localBuilder.LocalType; + Type cls = localBuilder.LocalType; if (cls is TypeBuilder || cls is EnumBuilder) { throw new ArgumentException(SR.NotSupported_OutputStreamUsingTypeBuilder); } - parameterTypes[0] = (Type)cls; + parameterTypes[0] = cls; MethodInfo? mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi == null) { @@ -1142,17 +1142,18 @@ namespace System.Reflection.Emit Emit(OpCodes.Ldfld, fld); } Type[] parameterTypes = new Type[1]; - object cls = fld.FieldType; + Type cls = fld.FieldType; if (cls is TypeBuilder || cls is EnumBuilder) { throw new NotSupportedException(SR.NotSupported_OutputStreamUsingTypeBuilder); } - parameterTypes[0] = (Type)cls; + parameterTypes[0] = cls; MethodInfo? mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi == null) { throw new ArgumentException(SR.Argument_EmitWriteLineType, nameof(fld)); } + Emit(OpCodes.Callvirt, mi); } -- 2.7.4