Allow for interface implementations in EventSource.WriteEventVarArgs (#25844) (#26056)
authorSung Yoon Whang <suwhang@microsoft.com>
Fri, 16 Aug 2019 23:30:53 +0000 (16:30 -0700)
committerGitHub <noreply@github.com>
Fri, 16 Aug 2019 23:30:53 +0000 (16:30 -0700)
* Allow for interface implementations in EventSource.WriteEventVarArgs

* Also account null ref types and nullable types

* fix error in comment and simplify first part of boolean logic

* Update src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs

Co-Authored-By: Noah Falk <noahfalk@users.noreply.github.com>
src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs

index b03011c..745836d 100644 (file)
@@ -2067,12 +2067,13 @@ namespace System.Diagnostics.Tracing
             {
                 Type pType = infos[i].ParameterType;
 
+                Type? argType = args[i]?.GetType();
+
                 // Checking to see if the Parameter types (from the Event method) match the supplied argument types.
-                // Fail if one of two things hold : either the argument type is not equal to the parameter type, or the 
-                // argument is null and the parameter type is non-nullable.
-                if ((args[i] != null && (args[i]!.GetType() != pType)) // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
-                    || (args[i] == null && (!(pType.IsGenericType && pType.GetGenericTypeDefinition() == typeof(Nullable<>))))
-                    )
+                // Fail if one of two things hold : either the argument type is not equal or assignable to the parameter type, or the 
+                // argument is null and the parameter type is a non-Nullable<T> value type.
+                if ((args[i] != null && !pType.IsAssignableFrom(argType))
+                    || (args[i] == null && !((pType.IsGenericType && pType.GetGenericTypeDefinition() == typeof(Nullable<>)) || !pType.IsValueType)))
                 {
                     typesMatch = false;
                     break;