I like to occasionally have a look at .NET libraries and glean some insight as to how I should be doing things. I mean those guys are the experts and I'm always ready to learn. But I'm a little stumped on these two methods:
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
private static String[] InternalReadAllLines(String path, Encoding encoding)
{
Contract.Requires(path != null);
Contract.Requires(encoding != null);
Contract.Requires(path.Length != 0);
.
.
.
}
[System.Security.SecuritySafeCritical]
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
public static IEnumerable<String> ReadLines(String path, Encoding encoding)
{
if (path == null)
throw new ArgumentNullException("path");
if (encoding == null)
throw new ArgumentNullException("encoding");
if (path.Length == 0)
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
Contract.EndContractBlock();
.
.
.
}
So I see this sweet way to ensure parameters are set Contract.Requires(...)
, really concise and clean. Then another method has a stack of if
statements followed by a Contract.EndContractBlock()
. Doesn't a BLOCK imply that there's a starting point?
Anyone know if the difference is by design for some specific reason or just different coding standard by different developer at different points in time?
NOTE: Whilst this is along the same lines as another question it's not an exact duplicate.