From ad025adbc7625ac6dea11f7090c344e9dc7b38b0 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 11 Jan 2020 08:45:52 -0500 Subject: [PATCH] Annotate System.Diagnostics.FileVersionInfo for nullable reference types (#1614) * Annotate System.Diagnostics.FileVersionInfo for nullable reference types * Address PR feedback --- .../ref/System.Diagnostics.FileVersionInfo.cs | 26 +++++----- .../System.Diagnostics.FileVersionInfo.csproj | 1 + .../System.Diagnostics.FileVersionInfo.csproj | 1 + .../Diagnostics/FileVersionInfo.Unix.cs | 16 +++--- .../Diagnostics/FileVersionInfo.Windows.cs | 3 +- .../src/System/Diagnostics/FileVersionInfo.cs | 52 +++++++++---------- 6 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.cs b/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.cs index 2b291cd2a6c..9a4d67c5844 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.cs +++ b/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.cs @@ -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; } } diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj b/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj index e7a966c3167..f4b463fa0d3 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj +++ b/src/libraries/System.Diagnostics.FileVersionInfo/ref/System.Diagnostics.FileVersionInfo.csproj @@ -1,5 +1,6 @@ + enable $(NetCoreAppCurrent)-Debug;$(NetCoreAppCurrent)-Release diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj index 66ea6de5384..efdb569758d 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj +++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj @@ -4,6 +4,7 @@ true $(NoWarn);CS1573 $(NetCoreAppCurrent)-Unix-Debug;$(NetCoreAppCurrent)-Unix-Release;$(NetCoreAppCurrent)-Windows_NT-Debug;$(NetCoreAppCurrent)-Windows_NT-Release + enable diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs index ecb3b821df7..149101fec97 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs +++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs @@ -191,7 +191,7 @@ namespace System.Diagnostics } /// Parses the version into its constituent parts. - 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 /// The metadata reader. /// The attribute. /// The value parsed from the attribute, if it could be retrieved; otherwise, the value is left unmodified. - 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; diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs index 1b6cd036a94..30cb65921b2 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs +++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs @@ -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)!; } } diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs index bd2faeb3d45..e99d185ed45 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs +++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.cs @@ -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 /// /// Gets the comments associated with the file. /// - public string Comments + public string? Comments { get { return _comments; } } @@ -52,7 +52,7 @@ namespace System.Diagnostics /// /// Gets the name of the company that produced the file. /// - public string CompanyName + public string? CompanyName { get { return _companyName; } } @@ -68,7 +68,7 @@ namespace System.Diagnostics /// /// Gets the description of the file. /// - public string FileDescription + public string? FileDescription { get { return _fileDescription; } } @@ -108,7 +108,7 @@ namespace System.Diagnostics /// /// Gets the file version number. /// - public string FileVersion + public string? FileVersion { get { return _fileVersion; } } @@ -116,7 +116,7 @@ namespace System.Diagnostics /// /// Gets the internal name of the file, if one exists. /// - public string InternalName + public string? InternalName { get { return _internalName; } } @@ -167,7 +167,7 @@ namespace System.Diagnostics /// /// Gets the default language string for the version info block. /// - public string Language + public string? Language { get { return _language; } } @@ -175,7 +175,7 @@ namespace System.Diagnostics /// /// Gets all copyright notices that apply to the specified file. /// - public string LegalCopyright + public string? LegalCopyright { get { return _legalCopyright; } } @@ -183,7 +183,7 @@ namespace System.Diagnostics /// /// Gets the trademarks and registered trademarks that apply to the file. /// - public string LegalTrademarks + public string? LegalTrademarks { get { return _legalTrademarks; } } @@ -191,7 +191,7 @@ namespace System.Diagnostics /// /// Gets the name the file was created with. /// - public string OriginalFilename + public string? OriginalFilename { get { return _originalFilename; } } @@ -199,7 +199,7 @@ namespace System.Diagnostics /// /// Gets information about a private version of the file. /// - public string PrivateBuild + public string? PrivateBuild { get { return _privateBuild; } } @@ -231,7 +231,7 @@ namespace System.Diagnostics /// /// Gets the name of the product this file is distributed with. /// - public string ProductName + public string? ProductName { get { return _productName; } } @@ -247,7 +247,7 @@ namespace System.Diagnostics /// /// Gets the version of the product this file is distributed with. /// - public string ProductVersion + public string? ProductVersion { get { return _productVersion; } } @@ -255,7 +255,7 @@ namespace System.Diagnostics /// /// Gets the special build information for the file. /// - public string SpecialBuild + public string? SpecialBuild { get { return _specialBuild; } } -- 2.34.1