Fix contructor attributes nullability in S.R.E.CustomAttributeBuilder (#34556)
authorMarcus Turewicz <24448509+marcusturewicz@users.noreply.github.com>
Mon, 6 Apr 2020 15:55:19 +0000 (01:55 +1000)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2020 15:55:19 +0000 (11:55 -0400)
* Fix contructor attributes nullability in S.R.E.CustomAttributeBuilder

Fixes #819

* Finalise nullable

* Updates ref

src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs
src/libraries/System.Reflection.Emit.ILGeneration/ref/System.Reflection.Emit.ILGeneration.cs

index 6a43ff4..506c98b 100644 (file)
@@ -34,7 +34,7 @@ namespace System.Reflection.Emit
         // public constructor to form the custom attribute with constructor, constructor
         // parameters and named properties.
         public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs,
-                                      PropertyInfo[] namedProperties, object[] propertyValues)
+                                      PropertyInfo[] namedProperties, object?[] propertyValues)
         {
             InitCustomAttributeBuilder(con, constructorArgs, namedProperties,
                                        propertyValues, Array.Empty<FieldInfo>(), Array.Empty<object>());
@@ -43,7 +43,7 @@ namespace System.Reflection.Emit
         // public constructor to form the custom attribute with constructor and constructor
         // parameters.
         public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs,
-                                      FieldInfo[] namedFields, object[] fieldValues)
+                                      FieldInfo[] namedFields, object?[] fieldValues)
         {
             InitCustomAttributeBuilder(con, constructorArgs, Array.Empty<PropertyInfo>(),
                                        Array.Empty<object>(), namedFields, fieldValues);
@@ -52,8 +52,8 @@ namespace System.Reflection.Emit
         // public constructor to form the custom attribute with constructor and constructor
         // parameters.
         public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs,
-                                      PropertyInfo[] namedProperties, object[] propertyValues,
-                                      FieldInfo[] namedFields, object[] fieldValues)
+                                      PropertyInfo[] namedProperties, object?[] propertyValues,
+                                      FieldInfo[] namedFields, object?[] fieldValues)
         {
             InitCustomAttributeBuilder(con, constructorArgs, namedProperties,
                                        propertyValues, namedFields, fieldValues);
@@ -97,8 +97,8 @@ namespace System.Reflection.Emit
         }
 
         internal void InitCustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs,
-                                                 PropertyInfo[] namedProperties, object[] propertyValues,
-                                                 FieldInfo[] namedFields, object[] fieldValues)
+                                                 PropertyInfo[] namedProperties, object?[] propertyValues,
+                                                 FieldInfo[] namedFields, object?[] fieldValues)
         {
             if (con == null)
                 throw new ArgumentNullException(nameof(con));
@@ -183,7 +183,7 @@ namespace System.Reflection.Emit
 
                 // Allow null for non-primitive types only.
                 Type propType = property.PropertyType;
-                object propertyValue = propertyValues[i];
+                object? propertyValue = propertyValues[i];
                 if (propertyValue == null && propType.IsValueType)
                     throw new ArgumentNullException("propertyValues[" + i + "]");
 
@@ -241,7 +241,7 @@ namespace System.Reflection.Emit
 
                 // Allow null for non-primitive types only.
                 Type fldType = namedField.FieldType;
-                object fieldValue = fieldValues[i];
+                object? fieldValue = fieldValues[i];
                 if (fieldValue == null && fldType.IsValueType)
                     throw new ArgumentNullException("fieldValues[" + i + "]");
 
index 210d8e3..363b53f 100644 (file)
@@ -10,9 +10,9 @@ namespace System.Reflection.Emit
     public partial class CustomAttributeBuilder
     {
         public CustomAttributeBuilder(System.Reflection.ConstructorInfo con, object?[] constructorArgs) { }
-        public CustomAttributeBuilder(System.Reflection.ConstructorInfo con, object?[] constructorArgs, System.Reflection.FieldInfo[] namedFields, object[] fieldValues) { }
-        public CustomAttributeBuilder(System.Reflection.ConstructorInfo con, object?[] constructorArgs, System.Reflection.PropertyInfo[] namedProperties, object[] propertyValues) { }
-        public CustomAttributeBuilder(System.Reflection.ConstructorInfo con, object?[] constructorArgs, System.Reflection.PropertyInfo[] namedProperties, object[] propertyValues, System.Reflection.FieldInfo[] namedFields, object[] fieldValues) { }
+        public CustomAttributeBuilder(System.Reflection.ConstructorInfo con, object?[] constructorArgs, System.Reflection.FieldInfo[] namedFields, object?[] fieldValues) { }
+        public CustomAttributeBuilder(System.Reflection.ConstructorInfo con, object?[] constructorArgs, System.Reflection.PropertyInfo[] namedProperties, object?[] propertyValues) { }
+        public CustomAttributeBuilder(System.Reflection.ConstructorInfo con, object?[] constructorArgs, System.Reflection.PropertyInfo[] namedProperties, object?[] propertyValues, System.Reflection.FieldInfo[] namedFields, object?[] fieldValues) { }
     }
     public partial class ILGenerator
     {