Remove reflection from RuntimeEventSource test. (#19692)
authorBrian Robbins <brianrob@microsoft.com>
Tue, 28 Aug 2018 01:22:10 +0000 (18:22 -0700)
committerGitHub <noreply@github.com>
Tue, 28 Aug 2018 01:22:10 +0000 (18:22 -0700)
tests/src/tracing/runtimeeventsource/RuntimeEventSourceTest.cs

index a081d88..18b78f4 100644 (file)
@@ -1,5 +1,3 @@
-#define REFLECTION
-
 using System;
 using System.IO;
 using System.Diagnostics.Tracing;
@@ -7,10 +5,6 @@ using System.Runtime.CompilerServices;
 using System.Threading;
 using Tracing.Tests.Common;
 
-#if REFLECTION
-using System.Reflection;
-#endif
-
 namespace Tracing.Tests
 {
     public sealed class RuntimeEventSourceTest
@@ -99,22 +93,11 @@ namespace Tracing.Tests
 
         protected override void OnEventWritten(EventWrittenEventArgs eventData)
         {
-            long osThreadId = -1;
-            DateTime timeStamp;
-#if REFLECTION
-            PropertyInfo threadProperty = typeof(EventWrittenEventArgs).GetProperty("OSThreadId");
-            MethodInfo threadMethod = threadProperty.GetGetMethod();
-            osThreadId = (long)threadMethod.Invoke(eventData, null);
-            PropertyInfo timeStampProperty = typeof(EventWrittenEventArgs).GetProperty("TimeStamp");
-            MethodInfo timeStampMethod = timeStampProperty.GetGetMethod();
-            timeStamp = (DateTime)timeStampMethod.Invoke(eventData, null);
-#endif
-
-            Console.WriteLine($"[{m_name}] ThreadID = {osThreadId} ID = {eventData.EventId} Name = {eventData.EventName}");
-            Console.WriteLine($"TimeStamp: {timeStamp.ToLocalTime()}");
+            Console.WriteLine($"[{m_name}] ThreadID = {eventData.OSThreadId} ID = {eventData.EventId} Name = {eventData.EventName}");
+            Console.WriteLine($"TimeStamp: {eventData.TimeStamp.ToLocalTime()}");
             Console.WriteLine($"LocalTime: {DateTime.Now}");
-            Console.WriteLine($"Difference: {DateTime.UtcNow - timeStamp}");
-            Assert.True("timeStamp < DateTime.UtcNow", timeStamp < DateTime.UtcNow);
+            Console.WriteLine($"Difference: {DateTime.UtcNow - eventData.TimeStamp}");
+            Assert.True("eventData.TimeStamp < DateTime.UtcNow", eventData.TimeStamp < DateTime.UtcNow);
             for (int i = 0; i < eventData.Payload.Count; i++)
             {
                 string payloadString = eventData.Payload[i] != null ? eventData.Payload[i].ToString() : string.Empty;
@@ -122,7 +105,6 @@ namespace Tracing.Tests
             }
             Console.WriteLine("\n");
 
-
             EventCount++;
         }
     }