Skip to content

Commit

Permalink
Merge pull request #1428 from mono/fixProcessStartinfo
Browse files Browse the repository at this point in the history
Update ProcessStartInfo to fix some inconsistency
  • Loading branch information
marek-safar committed Nov 26, 2014
2 parents d7efbfe + c9ff84d commit c092496
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
35 changes: 17 additions & 18 deletions mcs/class/System/System.Diagnostics/ProcessStartInfo.cs
Expand Up @@ -47,11 +47,11 @@ namespace System.Diagnostics
public sealed class ProcessStartInfo
{
/* keep these fields in this order and in sync with metadata/process.h */
private string arguments = "";
private string arguments;
private IntPtr error_dialog_parent_handle = (IntPtr)0;
private string filename = "";
private string verb = "";
private string working_directory = "";
private string filename;
private string verb;
private string working_directory;
private ProcessStringDictionary envVars;
private bool create_no_window = false;
private bool error_dialog = false;
Expand Down Expand Up @@ -87,7 +87,7 @@ public ProcessStartInfo(string filename, string arguments)
[NotifyParentPropertyAttribute (true)]
public string Arguments {
get {
return(arguments);
return arguments ?? string.Empty;
}
set {
arguments = value;
Expand Down Expand Up @@ -155,7 +155,7 @@ public ProcessStartInfo(string filename, string arguments)
[NotifyParentPropertyAttribute (true)]
public string FileName {
get {
return(filename);
return filename ?? string.Empty;
}
set {
filename = value;
Expand Down Expand Up @@ -187,7 +187,7 @@ public ProcessStartInfo(string filename, string arguments)
}

[DefaultValue (false)]
[MonitoringDescription ("Standart output of this process is redirected.")]
[MonitoringDescription ("Standard output of this process is redirected.")]
[NotifyParentPropertyAttribute (true)]
public bool RedirectStandardOutput {
get {
Expand Down Expand Up @@ -226,7 +226,7 @@ public ProcessStartInfo(string filename, string arguments)
[NotifyParentPropertyAttribute (true)]
public string Verb {
get {
return(verb);
return verb ?? string.Empty;
}
set {
verb = value;
Expand All @@ -238,21 +238,20 @@ public ProcessStartInfo(string filename, string arguments)
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
public string[] Verbs {
get {
string ext = filename == null | filename.Length == 0 ?
null : Path.GetExtension (filename);
if (ext == null)
return empty;

#if MOBILE
return empty;
#else

switch (Environment.OSVersion.Platform) {
case (PlatformID)4:
case (PlatformID)6:
case (PlatformID)128:
return empty; // no verb on non-Windows
default:
string ext = filename == null | filename.Length == 0 ?
null : Path.GetExtension (filename);
if (ext == null)
return empty;

RegistryKey rk = null, rk2 = null, rk3 = null;
try {
rk = Registry.ClassesRoot.OpenSubKey (ext);
Expand Down Expand Up @@ -292,10 +291,10 @@ public ProcessStartInfo(string filename, string arguments)
[NotifyParentPropertyAttribute (true)]
public string WorkingDirectory {
get {
return(working_directory);
return working_directory ?? string.Empty;
}
set {
working_directory = value == null ? String.Empty : value;
working_directory = value;
}
}

Expand All @@ -307,13 +306,13 @@ public ProcessStartInfo(string filename, string arguments)

[NotifyParentPropertyAttribute (true)]
public string UserName {
get { return username; }
get { return username ?? string.Empty; }
set { username = value; }
}

[NotifyParentPropertyAttribute (true)]
public string Domain {
get { return domain; }
get { return domain ?? string.Empty; }
set { domain = value; }
}

Expand Down
14 changes: 10 additions & 4 deletions mcs/class/System/Test/System.Diagnostics/ProcessStartInfoTest.cs
Expand Up @@ -20,11 +20,17 @@ namespace MonoTests.System.Diagnostics
public class ProcessStartInfoTest
{
[Test]
public void NullWorkingDirectory ()
public void NotNullCommonProperties ()
{
ProcessStartInfo info = new ProcessStartInfo ();
info.WorkingDirectory = null;
Assert.AreEqual (info.WorkingDirectory, String.Empty, "#1");
// Force FileName and Arguments to null. The others are null by default.
ProcessStartInfo info = new ProcessStartInfo (null, null);

Assert.AreEqual (info.Arguments, String.Empty, "#1");
Assert.AreEqual (info.Domain, String.Empty, "#2");
Assert.AreEqual (info.FileName, String.Empty, "#3");
Assert.AreEqual (info.UserName, String.Empty, "#4");
Assert.AreEqual (info.Verb, String.Empty, "#5");
Assert.AreEqual (info.WorkingDirectory, String.Empty, "#6");
}

#if NET_2_0
Expand Down

0 comments on commit c092496

Please sign in to comment.