From: Santiago Fernandez Madero Date: Tue, 25 Jun 2019 00:11:32 +0000 (-0500) Subject: Address last round of nullable feedback - S.Resources.ResourceManager, System.Reflect... X-Git-Tag: accepted/tizen/unified/20190813.215958~40^2~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=560467709747d75f5897e0d9cf441c91ac4e65a8;p=platform%2Fupstream%2Fcoreclr.git Address last round of nullable feedback - S.Resources.ResourceManager, System.Reflection.Emit and ILGeneration (#25318) * Address nullable feedback for System.Resources.ResourceManager * Address nullable feedback for System.Reflection.Emit.ILGeneration * Address nullable feedback for System.Reflection.Emit * PR Feedback and clean-up redundant casts --- diff --git a/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs b/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs index 49e8027..ae849e3 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/ResourceManager.cs @@ -98,7 +98,7 @@ namespace System.Resources public ResourceSet? lastResourceSet; } - protected string? BaseNameField; + protected string BaseNameField; protected Assembly? MainAssembly; // Need the assembly manifest sometimes. private Dictionary? _resourceSets; @@ -155,6 +155,7 @@ namespace System.Resources _lastUsedResourceCache = new CultureNameResourceSetPair(); ResourceManagerMediator mediator = new ResourceManagerMediator(this); _resourceGroveler = new ManifestBasedResourceGroveler(mediator); + BaseNameField = string.Empty; } // Constructs a Resource Manager for files beginning with @@ -256,7 +257,7 @@ namespace System.Resources } // Gets the base name for the ResourceManager. - public virtual string? BaseName + public virtual string BaseName { get { return BaseNameField; } } @@ -310,7 +311,7 @@ namespace System.Resources } } - public static ResourceManager CreateFileBasedResourceManager(string baseName, string resourceDir, Type usingResourceSet) + public static ResourceManager CreateFileBasedResourceManager(string baseName, string resourceDir, Type? usingResourceSet) { return new ResourceManager(baseName, resourceDir, usingResourceSet); } @@ -595,7 +596,7 @@ namespace System.Resources // public virtual string? GetString(string name) { - return GetString(name, (CultureInfo?)null); + return GetString(name, null); } // Looks up a resource value for a particular name. Looks in the @@ -670,13 +671,13 @@ namespace System.Resources // public virtual object? GetObject(string name) { - return GetObject(name, (CultureInfo?)null, true); + return GetObject(name, null, true); } // Looks up a resource value for a particular name. Looks in the // specified CultureInfo, and if not found, all parent CultureInfos. // Returns null if the resource wasn't found. - public virtual object? GetObject(string name, CultureInfo culture) + public virtual object? GetObject(string name, CultureInfo? culture) { return GetObject(name, culture, true); } @@ -746,7 +747,7 @@ namespace System.Resources public UnmanagedMemoryStream? GetStream(string name) { - return GetStream(name, (CultureInfo?)null); + return GetStream(name, null); } public UnmanagedMemoryStream? GetStream(string name, CultureInfo? culture) @@ -835,7 +836,7 @@ namespace System.Resources // this is weird because we have BaseNameField accessor above, but we're sticking // with it for compat. - internal string? BaseName + internal string BaseName { get { return _rm.BaseName; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs index 1da37d2..7f99526 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs @@ -24,7 +24,7 @@ namespace System.Reflection.Emit { // public constructor to form the custom attribute with constructor and constructor // parameters. - public CustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs) + public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs) { InitCustomAttributeBuilder(con, constructorArgs, new PropertyInfo[] { }, new object[] { }, @@ -33,7 +33,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, + public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues) { InitCustomAttributeBuilder(con, constructorArgs, namedProperties, @@ -42,7 +42,7 @@ namespace System.Reflection.Emit // public constructor to form the custom attribute with constructor and constructor // parameters. - public CustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs, + public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs, FieldInfo[] namedFields, object[] fieldValues) { InitCustomAttributeBuilder(con, constructorArgs, new PropertyInfo[] { }, @@ -51,7 +51,7 @@ namespace System.Reflection.Emit // public constructor to form the custom attribute with constructor and constructor // parameters. - public CustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs, + public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues, FieldInfo[] namedFields, object[] fieldValues) { @@ -96,7 +96,7 @@ namespace System.Reflection.Emit return t == typeof(object); } - internal void InitCustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs, + internal void InitCustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues, FieldInfo[] namedFields, object[] fieldValues) { @@ -126,7 +126,7 @@ namespace System.Reflection.Emit // Cache information used elsewhere. m_con = con; - m_constructorArgs = new object[constructorArgs.Length]; + m_constructorArgs = new object?[constructorArgs.Length]; Array.Copy(constructorArgs, 0, m_constructorArgs, 0, constructorArgs.Length); Type[] paramTypes; @@ -147,7 +147,7 @@ namespace System.Reflection.Emit // Now verify that the types of the actual parameters are compatible with the types of the formal parameters. for (i = 0; i < paramTypes.Length; i++) { - object constructorArg = constructorArgs[i]; + object? constructorArg = constructorArgs[i]; if (constructorArg == null) { if (paramTypes[i].IsValueType) @@ -551,7 +551,7 @@ namespace System.Reflection.Emit } internal ConstructorInfo m_con = null!; - internal object[] m_constructorArgs = null!; + internal object?[] m_constructorArgs = null!; internal byte[] m_blob = null!; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index c012744..0991b09 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -49,8 +49,8 @@ namespace System.Reflection.Emit // public DynamicMethod(string name, - Type returnType, - Type[] parameterTypes) + Type? returnType, + Type[]? parameterTypes) { Init(name, MethodAttributes.Public | MethodAttributes.Static, @@ -64,8 +64,8 @@ namespace System.Reflection.Emit } public DynamicMethod(string name, - Type returnType, - Type[] parameterTypes, + Type? returnType, + Type[]? parameterTypes, bool restrictedSkipVisibility) { Init(name, @@ -80,8 +80,8 @@ namespace System.Reflection.Emit } public DynamicMethod(string name, - Type returnType, - Type[] parameterTypes, + Type? returnType, + Type[]? parameterTypes, Module m) { if (m == null) @@ -99,8 +99,8 @@ namespace System.Reflection.Emit } public DynamicMethod(string name, - Type returnType, - Type[] parameterTypes, + Type? returnType, + Type[]? parameterTypes, Module m, bool skipVisibility) { @@ -121,8 +121,8 @@ namespace System.Reflection.Emit public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, - Type returnType, - Type[] parameterTypes, + Type? returnType, + Type[]? parameterTypes, Module m, bool skipVisibility) { @@ -141,8 +141,8 @@ namespace System.Reflection.Emit } public DynamicMethod(string name, - Type returnType, - Type[] parameterTypes, + Type? returnType, + Type[]? parameterTypes, Type owner) { if (owner == null) @@ -160,8 +160,8 @@ namespace System.Reflection.Emit } public DynamicMethod(string name, - Type returnType, - Type[] parameterTypes, + Type? returnType, + Type[]? parameterTypes, Type owner, bool skipVisibility) { @@ -182,8 +182,8 @@ namespace System.Reflection.Emit public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, - Type returnType, - Type[] parameterTypes, + Type? returnType, + Type[]? parameterTypes, Type owner, bool skipVisibility) { diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs index fc0b379..cfd5a94 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs @@ -741,7 +741,7 @@ namespace System.Reflection.Emit return m_tkMethod; } - public void SetParameters(params Type[]? parameterTypes) + public void SetParameters(params Type[] parameterTypes) { CheckContext(parameterTypes);