Annotate System.Diagnostics.FileVersionInfo for nullable reference types (#1614)
authorStephen Toub <stoub@microsoft.com>
Sat, 11 Jan 2020 13:45:52 +0000 (08:45 -0500)
committerGitHub <noreply@github.com>
Sat, 11 Jan 2020 13:45:52 +0000 (08:45 -0500)
* Annotate System.Diagnostics.FileVersionInfo for nullable reference types

* Address PR feedback

src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.cs
src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj
src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj
src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs
src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs
src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs

index 2b291cd2a6c166e9859016f109fdfd50072d8ed1..9a4d67c58442cd60df9e145689e54a8922519840 100644 (file)
@@ -10,33 +10,33 @@ namespace System.Diagnostics
     public sealed partial class FileVersionInfo
     {
         internal FileVersionInfo() { }
-        public string Comments { get { throw null; } }
-        public string CompanyName { get { throw null; } }
+        public string? Comments { get { throw null; } }
+        public string? CompanyName { get { throw null; } }
         public int FileBuildPart { get { throw null; } }
-        public string FileDescription { get { throw null; } }
+        public string? FileDescription { get { throw null; } }
         public int FileMajorPart { get { throw null; } }
         public int FileMinorPart { get { throw null; } }
         public string FileName { get { throw null; } }
         public int FilePrivatePart { get { throw null; } }
-        public string FileVersion { get { throw null; } }
-        public string InternalName { get { throw null; } }
+        public string? FileVersion { get { throw null; } }
+        public string? InternalName { get { throw null; } }
         public bool IsDebug { get { throw null; } }
         public bool IsPatched { get { throw null; } }
         public bool IsPreRelease { get { throw null; } }
         public bool IsPrivateBuild { get { throw null; } }
         public bool IsSpecialBuild { get { throw null; } }
-        public string Language { get { throw null; } }
-        public string LegalCopyright { get { throw null; } }
-        public string LegalTrademarks { get { throw null; } }
-        public string OriginalFilename { get { throw null; } }
-        public string PrivateBuild { get { throw null; } }
+        public string? Language { get { throw null; } }
+        public string? LegalCopyright { get { throw null; } }
+        public string? LegalTrademarks { get { throw null; } }
+        public string? OriginalFilename { get { throw null; } }
+        public string? PrivateBuild { get { throw null; } }
         public int ProductBuildPart { get { throw null; } }
         public int ProductMajorPart { get { throw null; } }
         public int ProductMinorPart { get { throw null; } }
-        public string ProductName { get { throw null; } }
+        public string? ProductName { get { throw null; } }
         public int ProductPrivatePart { get { throw null; } }
-        public string ProductVersion { get { throw null; } }
-        public string SpecialBuild { get { throw null; } }
+        public string? ProductVersion { get { throw null; } }
+        public string? SpecialBuild { get { throw null; } }
         public static System.Diagnostics.FileVersionInfo GetVersionInfo(string fileName) { throw null; }
         public override string ToString() { throw null; }
     }
index e7a966c31672ed85a1fc71e5162167f2a132e45f..f4b463fa0d35dc3ae11564507c9fabdebba3572c 100644 (file)
@@ -1,5 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
+    <Nullable>enable</Nullable>
     <Configurations>$(NetCoreAppCurrent)-Debug;$(NetCoreAppCurrent)-Release</Configurations>
   </PropertyGroup>
   <ItemGroup>
index 66ea6de53847fee66c85ac14d100e7471d121c28..efdb569758deab28bc28b4121d478312053395af 100644 (file)
@@ -4,6 +4,7 @@
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <NoWarn>$(NoWarn);CS1573</NoWarn>
     <Configurations>$(NetCoreAppCurrent)-Unix-Debug;$(NetCoreAppCurrent)-Unix-Release;$(NetCoreAppCurrent)-Windows_NT-Debug;$(NetCoreAppCurrent)-Windows_NT-Release</Configurations>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System\Diagnostics\FileVersionInfo.cs" />
index ecb3b821df7da5e5828a49a118afcc69e590b62f..149101fec97821cb29eb3e35928f5bce1bbaf476 100644 (file)
@@ -191,7 +191,7 @@ namespace System.Diagnostics
         }
 
         /// <summary>Parses the version into its constituent parts.</summary>
-        private static void ParseVersion(string versionString, out int major, out int minor, out int build, out int priv)
+        private static void ParseVersion(string? versionString, out int major, out int minor, out int build, out int priv)
         {
             // Relatively-forgiving parsing of a version:
             // - If there are more than four parts (separated by periods), all results are deemed 0
@@ -200,14 +200,14 @@ namespace System.Diagnostics
             // - Whitespace is treated like any other non-digit character and thus isn't ignored.
             // - Each component is parsed as a ushort, allowing for overflow.
 
-            string[] parts = versionString.Split(s_versionSeparators);
             major = minor = build = priv = 0;
-            if (parts.Length <= 4)
+
+            if (versionString != null)
             {
-                bool endedEarly;
-                if (parts.Length > 0)
+                string[] parts = versionString.Split(s_versionSeparators);
+                if (parts.Length <= 4 && parts.Length > 0)
                 {
-                    major = ParseUInt16UntilNonDigit(parts[0], out endedEarly);
+                    major = ParseUInt16UntilNonDigit(parts[0], out bool endedEarly);
                     if (!endedEarly && parts.Length > 1)
                     {
                         minor = ParseUInt16UntilNonDigit(parts[1], out endedEarly);
@@ -216,7 +216,7 @@ namespace System.Diagnostics
                             build = ParseUInt16UntilNonDigit(parts[2], out endedEarly);
                             if (!endedEarly && parts.Length > 3)
                             {
-                                priv = ParseUInt16UntilNonDigit(parts[3], out endedEarly);
+                                priv = ParseUInt16UntilNonDigit(parts[3], out _);
                             }
                         }
                     }
@@ -286,7 +286,7 @@ namespace System.Diagnostics
         /// <param name="reader">The metadata reader.</param>
         /// <param name="attr">The attribute.</param>
         /// <param name="value">The value parsed from the attribute, if it could be retrieved; otherwise, the value is left unmodified.</param>
-        private static void GetStringAttributeArgumentValue(MetadataReader reader, CustomAttribute attr, ref string value)
+        private static void GetStringAttributeArgumentValue(MetadataReader reader, CustomAttribute attr, ref string? value)
         {
             EntityHandle ctorHandle = attr.Constructor;
             BlobHandle signature;
index 1b6cd036a94a27284ad39a0479fe15bf2860085a..30cb65921b2edc8bbe06ecea3b4caca633aa7bfe 100644 (file)
@@ -4,7 +4,6 @@
 
 using System.Globalization;
 using System.Runtime.InteropServices;
-using System.Text;
 
 namespace System.Diagnostics
 {
@@ -106,7 +105,7 @@ namespace System.Diagnostics
             {
                 if (memRef != IntPtr.Zero)
                 {
-                    return Marshal.PtrToStringUni(memRef);
+                    return Marshal.PtrToStringUni(memRef)!;
                 }
             }
 
index bd2faeb3d4580442790c4b08bebcec6ca093da53..e99d185ed45f2ffe753a1b3042211cade38f33f4 100644 (file)
@@ -14,19 +14,19 @@ namespace System.Diagnostics
     {
         private readonly string _fileName;
 
-        private string _companyName;
-        private string _fileDescription;
-        private string _fileVersion;
-        private string _internalName;
-        private string _legalCopyright;
-        private string _originalFilename;
-        private string _productName;
-        private string _productVersion;
-        private string _comments;
-        private string _legalTrademarks;
-        private string _privateBuild;
-        private string _specialBuild;
-        private string _language;
+        private string? _companyName;
+        private string? _fileDescription;
+        private string? _fileVersion;
+        private string? _internalName;
+        private string? _legalCopyright;
+        private string? _originalFilename;
+        private string? _productName;
+        private string? _productVersion;
+        private string? _comments;
+        private string? _legalTrademarks;
+        private string? _privateBuild;
+        private string? _specialBuild;
+        private string? _language;
         private int _fileMajor;
         private int _fileMinor;
         private int _fileBuild;
@@ -44,7 +44,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the comments associated with the file.
         /// </summary>
-        public string Comments
+        public string? Comments
         {
             get { return _comments; }
         }
@@ -52,7 +52,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the name of the company that produced the file.
         /// </summary>
-        public string CompanyName
+        public string? CompanyName
         {
             get { return _companyName; }
         }
@@ -68,7 +68,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the description of the file.
         /// </summary>
-        public string FileDescription
+        public string? FileDescription
         {
             get { return _fileDescription; }
         }
@@ -108,7 +108,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the file version number.
         /// </summary>
-        public string FileVersion
+        public string? FileVersion
         {
             get { return _fileVersion; }
         }
@@ -116,7 +116,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the internal name of the file, if one exists.
         /// </summary>
-        public string InternalName
+        public string? InternalName
         {
             get { return _internalName; }
         }
@@ -167,7 +167,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the default language string for the version info block.
         /// </summary>
-        public string Language
+        public string? Language
         {
             get { return _language; }
         }
@@ -175,7 +175,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets all copyright notices that apply to the specified file.
         /// </summary>
-        public string LegalCopyright
+        public string? LegalCopyright
         {
             get { return _legalCopyright; }
         }
@@ -183,7 +183,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the trademarks and registered trademarks that apply to the file.
         /// </summary>
-        public string LegalTrademarks
+        public string? LegalTrademarks
         {
             get { return _legalTrademarks; }
         }
@@ -191,7 +191,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the name the file was created with.
         /// </summary>
-        public string OriginalFilename
+        public string? OriginalFilename
         {
             get { return _originalFilename; }
         }
@@ -199,7 +199,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets information about a private version of the file.
         /// </summary>
-        public string PrivateBuild
+        public string? PrivateBuild
         {
             get { return _privateBuild; }
         }
@@ -231,7 +231,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the name of the product this file is distributed with.
         /// </summary>
-        public string ProductName
+        public string? ProductName
         {
             get { return _productName; }
         }
@@ -247,7 +247,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the version of the product this file is distributed with.
         /// </summary>
-        public string ProductVersion
+        public string? ProductVersion
         {
             get { return _productVersion; }
         }
@@ -255,7 +255,7 @@ namespace System.Diagnostics
         /// <summary>
         /// Gets the special build information for the file.
         /// </summary>
-        public string SpecialBuild
+        public string? SpecialBuild
         {
             get { return _specialBuild; }
         }