<argument>ILLink</argument>
<argument>IL2070</argument>
<property name="Scope">member</property>
- <property name="Target">M:System.Diagnostics.Tracing.NullableTypeInfo.#ctor(System.Type,System.Collections.Generic.List{System.Type})</property>
- </attribute>
- <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
- <argument>ILLink</argument>
- <argument>IL2070</argument>
- <property name="Scope">member</property>
<property name="Target">M:System.Diagnostics.Tracing.TypeAnalysis.#ctor(System.Type,System.Diagnostics.Tracing.EventDataAttribute,System.Collections.Generic.List{System.Type})</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
- <argument>IL2072</argument>
- <property name="Scope">member</property>
- <property name="Target">M:System.Diagnostics.Tracing.NullableTypeInfo.WriteData(System.Diagnostics.Tracing.PropertyValue)</property>
- </attribute>
- <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
- <argument>ILLink</argument>
<argument>IL2075</argument>
<property name="Scope">member</property>
<property name="Target">M:Internal.Runtime.InteropServices.ComActivator.ClassRegistrationScenarioForType(Internal.Runtime.InteropServices.ComActivationContext,System.Boolean)</property>
#if ES_BUILD_STANDALONE
using System;
using System.Diagnostics;
+using System.Runtime.Serialization;
#endif
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
+using System.Runtime.CompilerServices;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
internal sealed class NullableTypeInfo : TraceLoggingTypeInfo
{
private readonly TraceLoggingTypeInfo valueInfo;
- private readonly Func<PropertyValue, PropertyValue> valueGetter;
public NullableTypeInfo(Type type, List<Type> recursionCheck)
: base(type)
Type[] typeArgs = type.GenericTypeArguments;
Debug.Assert(typeArgs.Length == 1);
this.valueInfo = TraceLoggingTypeInfo.GetInstance(typeArgs[0], recursionCheck);
- this.valueGetter = PropertyValue.GetPropertyGetter(type.GetProperty("Value")!);
}
public override void WriteMetadata(
this.valueInfo.WriteMetadata(group, "Value", format);
}
+#if !ES_BUILD_STANDALONE
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072:UnrecognizedReflectionPattern",
+ Justification = "The underlying type of Nullable<T> must be defaultable")]
+#endif
public override void WriteData(PropertyValue value)
{
- // It's not currently possible to get the HasValue property of a nullable type through reflection when the
- // value is null. Instead, we simply check that the nullable is not null.
- bool hasValue = value.ReferenceValue != null;
+ object? refVal = value.ReferenceValue;
+ bool hasValue = refVal is not null;
TraceLoggingDataCollector.AddScalar(hasValue);
- PropertyValue val = hasValue ? valueGetter(value) : valueInfo.PropertyValueFactory(Activator.CreateInstance(valueInfo.DataType));
+ PropertyValue val = valueInfo.PropertyValueFactory(hasValue
+ ? refVal
+#if ES_BUILD_STANDALONE
+ : FormatterServices.GetUninitializedObject(valueInfo.DataType));
+ #else
+ : RuntimeHelpers.GetUninitializedObject(valueInfo.DataType));
+ #endif
this.valueInfo.WriteData(val);
}
}