Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions Microsoft.Research/Contracts/MsCorlib/System.IO.Directory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace System.IO
{
#if !SILVERLIGHT_4_0_WP
#if !SILVERLIGHT_3_0
// Summary:
// Specifies whether to search the current directory, or the current directory
// and all subdirectories.
Expand Down Expand Up @@ -91,7 +91,21 @@ public static String[] GetLogicalDrives()
}
#endif

#if !SILVERLIGHT_4_0 && !SILVERLIGHT_5_0
#if !SILVERLIGHT
public static String[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
{
Contract.Requires(!String.IsNullOrEmpty(path));
Contract.Requires(searchPattern != null);
Contract.Requires(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly);
Contract.Ensures(Contract.Result<string[]>() != null);
Contract.Ensures(Contract.ForAll(Contract.Result<string[]>(), file => file != null));
Contract.EnsuresOnThrow<System.IO.IOException>(true, @"path is a file name.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this message is correct? It seems slightly misleading to me because it doesn't tell what the error type is...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's what MSDN says, although honestly I just copied and pasted this part without much thinking. Looking closer, I'm not sure if there is much value in adding EnsuresOnThrow in this form.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. This stuff looked weird for me as well, but then I've searched thought this repo and found that this is a canonical way to express possible exceptions.

My point was more about the message that is absolutely unclear, but because the official documentation is saying that, I'm not sure what we can do. I would prefer to have more clear message but have no idea what this message should looks like.

Contract.EnsuresOnThrow<System.IO.PathTooLongException>(true, @"The specified path, file name, or both exceed the system-defined maximum length.");
Contract.EnsuresOnThrow<System.IO.DirectoryNotFoundException>(true, @"The specified path is invalid (for example, it is on an unmapped drive.");

return default(String[]);
}
#endif
public static String[] GetFileSystemEntries(string path, string searchPattern)
{
Contract.Requires(!String.IsNullOrEmpty(path));
Expand All @@ -116,6 +130,21 @@ public static String[] GetFileSystemEntries(string path)

return default(String[]);
}
#if !SILVERLIGHT
public static String[] GetDirectories(string path, string searchPattern, SearchOption searchOption)
{
Contract.Requires(!String.IsNullOrEmpty(path));
Contract.Requires(searchPattern != null);
Contract.Requires(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly);
Contract.Ensures(Contract.Result<string[]>() != null);
Contract.Ensures(Contract.ForAll(Contract.Result<string[]>(), dir => dir != null));
Contract.EnsuresOnThrow<System.IO.IOException>(true, @"path is a file name.");
Contract.EnsuresOnThrow<System.IO.PathTooLongException>(true, @"The specified path, file name, or both exceed the system-defined maximum length.");
Contract.EnsuresOnThrow<System.IO.DirectoryNotFoundException>(true, @"The specified path is invalid (for example, it is on an unmapped drive.");

return default(String[]);
}
#endif
public static String[] GetDirectories(string path, string searchPattern)
{
Contract.Requires(!String.IsNullOrEmpty(path));
Expand All @@ -139,6 +168,21 @@ public static String[] GetDirectories(string path)

return default(String[]);
}
#if !SILVERLIGHT
public static String[] GetFiles(string path, string searchPattern, SearchOption searchOption)
{
Contract.Requires(!String.IsNullOrEmpty(path));
Contract.Requires(searchPattern != null);
Contract.Requires(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly);
Contract.Ensures(Contract.Result<string[]>() != null);
Contract.Ensures(Contract.ForAll(Contract.Result<string[]>(), file => file != null));
Contract.EnsuresOnThrow<System.IO.IOException>(true, @"path is a file name.");
Contract.EnsuresOnThrow<System.IO.PathTooLongException>(true, @"The specified path, file name, or both exceed the system-defined maximum length.");
Contract.EnsuresOnThrow<System.IO.DirectoryNotFoundException>(true, @"The specified path is invalid (for example, it is on an unmapped drive.");

return default(String[]);
}
#endif
public static String[] GetFiles(string path, string searchPattern)
{
Contract.Requires(!String.IsNullOrEmpty(path));
Expand All @@ -161,7 +205,6 @@ public static String[] GetFiles(string path)
Contract.EnsuresOnThrow<System.IO.DirectoryNotFoundException>(true, @"The specified path is invalid (for example, it is on an unmapped drive.");
return default(String[]);
}
#endif

#if !SILVERLIGHT
public static DateTime GetLastAccessTimeUtc(string path)
Expand Down