@@ -269,7 +269,6 @@ public override void WriteData(TraceLoggingDataCollector collector, PropertyValu
269
269
internal sealed class NullableTypeInfo : TraceLoggingTypeInfo
270
270
{
271
271
private readonly TraceLoggingTypeInfo valueInfo ;
272
- private readonly Func < PropertyValue , PropertyValue > hasValueGetter ;
273
272
private readonly Func < PropertyValue , PropertyValue > valueGetter ;
274
273
275
274
public NullableTypeInfo ( Type type , List < Type > recursionCheck )
@@ -278,7 +277,6 @@ public NullableTypeInfo(Type type, List<Type> recursionCheck)
278
277
var typeArgs = type . GenericTypeArguments ;
279
278
Debug . Assert ( typeArgs . Length == 1 ) ;
280
279
this . valueInfo = TraceLoggingTypeInfo . GetInstance ( typeArgs [ 0 ] , recursionCheck ) ;
281
- this . hasValueGetter = PropertyValue . GetPropertyGetter ( type . GetTypeInfo ( ) . GetDeclaredProperty ( "HasValue" ) ) ;
282
280
this . valueGetter = PropertyValue . GetPropertyGetter ( type . GetTypeInfo ( ) . GetDeclaredProperty ( "Value" ) ) ;
283
281
}
284
282
@@ -294,9 +292,11 @@ public override void WriteMetadata(
294
292
295
293
public override void WriteData ( TraceLoggingDataCollector collector , PropertyValue value )
296
294
{
297
- var hasValue = hasValueGetter ( value ) ;
295
+ // It's not currently possible to get the HasValue property of a nullable type through reflection when the
296
+ // value is null. Instead, we simply check that the nullable is not null.
297
+ var hasValue = value . ReferenceValue != null ;
298
298
collector . AddScalar ( hasValue ) ;
299
- var val = hasValue . ScalarValue . AsBoolean ? valueGetter ( value ) : valueInfo . PropertyValueFactory ( Activator . CreateInstance ( valueInfo . DataType ) ) ;
299
+ var val = hasValue ? valueGetter ( value ) : valueInfo . PropertyValueFactory ( Activator . CreateInstance ( valueInfo . DataType ) ) ;
300
300
this . valueInfo . WriteData ( collector , val ) ;
301
301
}
302
302
}
0 commit comments