Make DisplayUnits string.Empty by default instead of null (#25104)
authorSung Yoon Whang <suwhang@microsoft.com>
Fri, 14 Jun 2019 17:30:31 +0000 (10:30 -0700)
committerGitHub <noreply@github.com>
Fri, 14 Jun 2019 17:30:31 +0000 (10:30 -0700)
* Make DisplayUnits string.Empty by default instead of null

* PR feedback on DisplayName and setter validation

src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/DiagnosticCounter.cs

index ade22c7..5a4429f 100644 (file)
@@ -45,6 +45,7 @@ namespace System.Diagnostics.Tracing
             _group = CounterGroup.GetCounterGroup(eventSource);
             _group.Add(this);
             Name = name;
+            DisplayUnits = string.Empty;
             EventSource = eventSource;
         }
 
@@ -75,9 +76,29 @@ namespace System.Diagnostics.Tracing
             }
         }
 
-        public string? DisplayName { get; set; }
+        private string _displayName = "";
+        public string DisplayName
+        {
+            set
+            {
+                if (value == null)
+                    throw new ArgumentException("Cannot set null as DisplayName");
+                _displayName = value;
+            }
+            get { return _displayName; }
+        }
 
-        public string? DisplayUnits { get; set; }
+        private string _displayUnits = "";
+        public string DisplayUnits
+        {
+            set
+            {
+                if (value == null)
+                    throw new ArgumentException("Cannot set null as DisplayUnits");
+                _displayUnits = value;
+            }
+            get { return _displayUnits; }
+        }
 
         public string Name { get; }