Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

re #32 switched to LiteGuard.Source.0.5.0.nupkg

  • Loading branch information...
commit 4d56cef8c26eb3f279bd6c07be6f91eaedb805d3 1 parent bd0c67c
@adamralph adamralph authored
Showing with 790 additions and 154 deletions.
  1. BIN  packages/LiteGuard.0.4.0/LiteGuard.0.4.0.nupkg
  2. BIN  packages/LiteGuard.0.4.0/lib/net35/LiteGuard.dll
  3. +0 −59 packages/LiteGuard.0.4.0/lib/net35/LiteGuard.xml
  4. BIN  packages/LiteGuard.Source.0.5.0/LiteGuard.Source.0.5.0.nupkg
  5. +9 −8 packages/{LiteGuard.0.4.0/LiteGuard.0.4.0.nuspec → LiteGuard.Source.0.5.0/LiteGuard.Source.0.5.0.nuspec}
  6. +98 −0 packages/LiteGuard.Source.0.5.0/content/net35/Guard.cs.pp
  7. +102 −0 src/Xbehave.Net35/Guard.cs
  8. +1 −3 src/Xbehave.Net35/Xbehave.Net35.csproj
  9. +1 −1  src/Xbehave.Net35/packages.config
  10. +102 −0 src/Xbehave.Net40/Guard.cs
  11. +4 −4 src/Xbehave.Net40/ScenarioAttribute.cs
  12. +1 −3 src/Xbehave.Net40/Xbehave.Net40.csproj
  13. +1 −1  src/Xbehave.Net40/packages.config
  14. +102 −0 src/Xbehave.Net45/Guard.cs
  15. +1 −3 src/Xbehave.Net45/Xbehave.Net45.csproj
  16. +1 −1  src/Xbehave.Net45/packages.config
  17. +102 −0 src/Xbehave.Sdk.Net35/Guard.cs
  18. +1 −3 src/Xbehave.Sdk.Net35/Xbehave.Sdk.Net35.csproj
  19. +1 −1  src/Xbehave.Sdk.Net35/packages.config
  20. +2 −2 src/Xbehave.Sdk.Net40/Argument.cs
  21. +45 −45 src/Xbehave.Sdk.Net40/Command.cs
  22. +1 −1  src/Xbehave.Sdk.Net40/Context.cs
  23. +1 −1  src/Xbehave.Sdk.Net40/ContextFactory.cs
  24. +2 −2 src/Xbehave.Sdk.Net40/CurrentScenario.cs
  25. +102 −0 src/Xbehave.Sdk.Net40/Guard.cs
  26. +1 −1  src/Xbehave.Sdk.Net40/Step.cs
  27. +2 −2 src/Xbehave.Sdk.Net40/StepCommand.cs
  28. +1 −1  src/Xbehave.Sdk.Net40/TeardownCommand.cs
  29. +1 −3 src/Xbehave.Sdk.Net40/Xbehave.Sdk.Net40.csproj
  30. +1 −1  src/Xbehave.Sdk.Net40/packages.config
  31. +102 −0 src/Xbehave.Sdk.Net45/Guard.cs
  32. +1 −3 src/Xbehave.Sdk.Net45/Xbehave.Sdk.Net45.csproj
  33. +1 −1  src/Xbehave.Sdk.Net45/packages.config
  34. +0 −2  src/Xbehave.Windows_NT.nuspec
  35. +0 −2  src/Xbehave.nuspec
View
BIN  packages/LiteGuard.0.4.0/LiteGuard.0.4.0.nupkg
Binary file not shown
View
BIN  packages/LiteGuard.0.4.0/lib/net35/LiteGuard.dll
Binary file not shown
View
59 packages/LiteGuard.0.4.0/lib/net35/LiteGuard.xml
@@ -1,59 +0,0 @@
-<?xml version="1.0"?>
-<doc>
- <assembly>
- <name>LiteGuard</name>
- </assembly>
- <members>
- <member name="T:LiteGuard.Guard">
- <summary>
- Provides guard clauses.
- </summary>
- </member>
- <member name="M:LiteGuard.Guard.AgainstNullArgument``1(System.String,``0)">
- <summary>
- Guards against a null argument.
- </summary>
- <typeparam name="TArgument">The type of the argument.</typeparam>
- <param name="parameterName">Name of the parameter.</param>
- <param name="argument">The argument.</param>
- <exception cref="T:System.ArgumentNullException"><paramref name="argument"/> is <c>null</c>.</exception>
- <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
- </member>
- <member name="M:LiteGuard.Guard.AgainstNullArgumentIfNullable``1(System.String,``0)">
- <summary>
- Guards against a null argument if <typeparamref name="TArgument"/> is a nullable type.
- </summary>
- <typeparam name="TArgument">The type of the argument.</typeparam>
- <param name="parameterName">Name of the parameter.</param>
- <param name="argument">The argument.</param>
- <exception cref="T:System.ArgumentNullException"><paramref name="argument"/> is <c>null</c>.</exception>
- <remarks>
- Performs a type check to avoid boxing of value type objects.
- </remarks>
- </member>
- <member name="M:LiteGuard.Guard.AgainstNullArgumentProperty``1(System.String,System.String,``0)">
- <summary>
- Guards against a null argument property value.
- </summary>
- <typeparam name="TProperty">The type of the property.</typeparam>
- <param name="parameterName">Name of the parameter.</param>
- <param name="propertyName">Name of the property.</param>
- <param name="argumentProperty">The argument property.</param>
- <exception cref="T:System.ArgumentException"><paramref name="argumentProperty"/> is <c>null</c>.</exception>
- <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
- </member>
- <member name="M:LiteGuard.Guard.AgainstNullArgumentPropertyIfNullable``1(System.String,System.String,``0)">
- <summary>
- Guards against a null argument property value if <typeparamref name="TProperty"/> is a nullable type.
- </summary>
- <typeparam name="TProperty">The type of the property.</typeparam>
- <param name="parameterName">Name of the parameter.</param>
- <param name="propertyName">Name of the property.</param>
- <param name="argumentProperty">The argument property.</param>
- <exception cref="T:System.ArgumentException"><paramref name="argumentProperty"/> is <c>null</c>.</exception>
- <remarks>
- Performs a type check to avoid boxing of value type objects.
- </remarks>
- </member>
- </members>
-</doc>
View
BIN  packages/LiteGuard.Source.0.5.0/LiteGuard.Source.0.5.0.nupkg
Binary file not shown
View
17 ...es/LiteGuard.0.4.0/LiteGuard.0.4.0.nuspec → ...ource.0.5.0/LiteGuard.Source.0.5.0.nuspec
@@ -1,21 +1,22 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
- <id>LiteGuard</id>
- <version>0.4.0</version>
- <title>LiteGuard</title>
+ <id>LiteGuard.Source</id>
+ <version>0.5.0</version>
+ <title>LiteGuard.Source</title>
<authors>Adam Ralph, LiteGuard contributors</authors>
<owners>Adam Ralph, LiteGuard contributors</owners>
<projectUrl>https://github.com/liteguard/liteguard</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Why, it's lighter than air! The guard clause library which stands out from the crowd like the faintest passing whisper. You'll hardly know it's there!
We all have to do our bit in working toward the ultimate number of published guard clause libraries which, at current estimates, is somewhere in the region of 6.02214129(27) × 10^23.
-The aim of LiteGuard is to be the most unambiguous, simple and lightweight guard clause library available. See the project site for details.</description>
- <releaseNotes>New clauses AgainstNullArgumentIfNullable() and AgainstNullArgumentPropertyIfNullable() with unrestricted type parameters for use in generic methods.</releaseNotes>
+The aim of LiteGuard is to be the most simple, unambiguous and lightweight guard clause library available. See the project site for details.
+This is the LiteGuard source code package. LiteGuard is also available as a binary package named 'LiteGuard'. If your project is an application or library which is not packaged and/or exported for use in other solutions then the binary package is usually the best choice. If you are writing a library which is packaged and/or exported for use in other solutions then the source code package is usually the best choice.
+After installing this package you may change the source code as required to match your coding conventions.</description>
+ <releaseNotes>Enhancement: Add source code package - https://github.com/liteguard/liteguard/issues/5/</releaseNotes>
<copyright>Copyright (c) LiteGuard contributors. (lightguard.ch@gmail.com)</copyright>
+ <language />
<tags>guard clause arguments light avogadro</tags>
- <references>
- <reference file="LiteGuard.dll" />
- </references>
+ <references />
</metadata>
</package>
View
98 packages/LiteGuard.Source.0.5.0/content/net35/Guard.cs.pp
@@ -0,0 +1,98 @@
+namespace $rootnamespace$
+{
+ using System;
+ using System.Diagnostics;
+ using System.Globalization;
+
+ /// <summary>
+ /// Provides guard clauses.
+ /// </summary>
+ internal static class Guard
+ {
+ /// <summary>
+ /// Guards against a null argument.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgument<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument) where TArgument : class
+ {
+ if (argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument if <typeparamref name="TArgument" /> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentIfNullable<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument)
+ {
+ if (typeof(TArgument).IsNullableType() && argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentProperty<TProperty>(string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ where TProperty : class
+ {
+ if (argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value if <typeparamref name="TProperty"/> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentPropertyIfNullable<TProperty>(
+ string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ {
+ if (typeof(TProperty).IsNullableType() && argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ private static bool IsNullableType(this Type type)
+ {
+ return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
+ }
+
+ // NOTE: when applied to a parameter, this attribute provides an indication to code analysis that the argument has been null checked
+ private sealed class ValidatedNotNullAttribute : Attribute
+ {
+ }
+ }
+}
View
102 src/Xbehave.Net35/Guard.cs
@@ -0,0 +1,102 @@
+// <copyright file="Guard.cs" company="xBehave.net contributors">
+// Copyright (c) xBehave.net contributors. All rights reserved.
+// </copyright>
+
+namespace Xbehave
+{
+ using System;
+ using System.Diagnostics;
+ using System.Globalization;
+
+ /// <summary>
+ /// Provides guard clauses.
+ /// </summary>
+ internal static class Guard
+ {
+ /// <summary>
+ /// Guards against a null argument.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgument<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument) where TArgument : class
+ {
+ if (argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument if <typeparamref name="TArgument" /> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentIfNullable<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument)
+ {
+ if (typeof(TArgument).IsNullableType() && argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentProperty<TProperty>(string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ where TProperty : class
+ {
+ if (argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value if <typeparamref name="TProperty"/> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentPropertyIfNullable<TProperty>(
+ string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ {
+ if (typeof(TProperty).IsNullableType() && argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ private static bool IsNullableType(this Type type)
+ {
+ return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
+ }
+
+ // NOTE: when applied to a parameter, this attribute provides an indication to code analysis that the argument has been null checked
+ private sealed class ValidatedNotNullAttribute : Attribute
+ {
+ }
+ }
+}
View
4 src/Xbehave.Net35/Xbehave.Net35.csproj
@@ -46,9 +46,6 @@
<AssemblyOriginatorKeyFile>..\Xbehave.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="LiteGuard">
- <HintPath>..\..\packages\LiteGuard.0.4.0\lib\net35\LiteGuard.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="xunit, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.1.9.1\lib\net20\xunit.dll</HintPath>
@@ -64,6 +61,7 @@
<Compile Include="..\Xbehave.Net40\BackgroundAttribute.cs">
<Link>BackgroundAttribute.cs</Link>
</Compile>
+ <Compile Include="Guard.cs" />
<None Include="..\Xbehave.Net40\Sandbox\DynamicStringExtensions.cs">
<Link>Sandbox\DynamicStringExtensions.cs</Link>
</None>
View
2  src/Xbehave.Net35/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="LiteGuard" version="0.4.0" targetFramework="net35" />
+ <package id="LiteGuard.Source" version="0.5.0" targetFramework="net35" />
<package id="StyleCop.MSBuild" version="4.7.44.1" targetFramework="net35" />
<package id="xunit" version="1.9.1" targetFramework="net35" />
<package id="xunit.extensions" version="1.9.1" targetFramework="net35" />
View
102 src/Xbehave.Net40/Guard.cs
@@ -0,0 +1,102 @@
+// <copyright file="Guard.cs" company="xBehave.net contributors">
+// Copyright (c) xBehave.net contributors. All rights reserved.
+// </copyright>
+
+namespace Xbehave
+{
+ using System;
+ using System.Diagnostics;
+ using System.Globalization;
+
+ /// <summary>
+ /// Provides guard clauses.
+ /// </summary>
+ internal static class Guard
+ {
+ /// <summary>
+ /// Guards against a null argument.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgument<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument) where TArgument : class
+ {
+ if (argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument if <typeparamref name="TArgument" /> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentIfNullable<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument)
+ {
+ if (typeof(TArgument).IsNullableType() && argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentProperty<TProperty>(string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ where TProperty : class
+ {
+ if (argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value if <typeparamref name="TProperty"/> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentPropertyIfNullable<TProperty>(
+ string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ {
+ if (typeof(TProperty).IsNullableType() && argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ private static bool IsNullableType(this Type type)
+ {
+ return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
+ }
+
+ // NOTE: when applied to a parameter, this attribute provides an indication to code analysis that the argument has been null checked
+ private sealed class ValidatedNotNullAttribute : Attribute
+ {
+ }
+ }
+}
View
8 src/Xbehave.Net40/ScenarioAttribute.cs
@@ -72,8 +72,8 @@ protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo m
/// <returns>An instance of <see cref="IEnumerable{ITestCommand}"/> representing the backgrounds associated with the <paramref name="method"/>.</returns>
protected virtual IEnumerable<ITestCommand> EnumerateBackgroundCommands(IMethodInfo method)
{
- LiteGuard.Guard.AgainstNullArgument("method", method);
- LiteGuard.Guard.AgainstNullArgumentProperty("method", "Class", method.Class);
+ Guard.AgainstNullArgument("method", method);
+ Guard.AgainstNullArgumentProperty("method", "Class", method.Class);
return method.Class.GetMethods().SelectMany(
candidateMethod => candidateMethod.GetCustomAttributes(typeof(BackgroundAttribute))
@@ -89,8 +89,8 @@ protected virtual IEnumerable<ITestCommand> EnumerateBackgroundCommands(IMethodI
/// <remarks>This method may be overridden.</remarks>
protected virtual IEnumerable<ICommand> EnumerateScenarioCommands(IMethodInfo method)
{
- LiteGuard.Guard.AgainstNullArgument("method", method);
- LiteGuard.Guard.AgainstNullArgumentProperty("method", "MethodInfo", method.MethodInfo);
+ Guard.AgainstNullArgument("method", method);
+ Guard.AgainstNullArgumentProperty("method", "MethodInfo", method.MethodInfo);
var parameters = method.MethodInfo.GetParameters();
if (!parameters.Any())
View
4 src/Xbehave.Net40/Xbehave.Net40.csproj
@@ -46,9 +46,6 @@
<AssemblyOriginatorKeyFile>..\Xbehave.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="LiteGuard">
- <HintPath>..\..\packages\LiteGuard.0.4.0\lib\net35\LiteGuard.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="xunit, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.1.9.1\lib\net20\xunit.dll</HintPath>
@@ -64,6 +61,7 @@
<Compile Include="BackgroundAttribute.cs" />
<Compile Include="DisposableExtensions.cs" />
<Compile Include="ExampleAttribute.cs" />
+ <Compile Include="Guard.cs" />
<Compile Include="Helper.cs" />
<Compile Include="StepExtensions.cs" />
<Compile Include="StringExtensions.cs" />
View
2  src/Xbehave.Net40/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="LiteGuard" version="0.4.0" targetFramework="net40" />
+ <package id="LiteGuard.Source" version="0.5.0" targetFramework="net40" />
<package id="StyleCop.MSBuild" version="4.7.44.1" targetFramework="net40" />
<package id="xunit" version="1.9.1" targetFramework="net40" />
<package id="xunit.extensions" version="1.9.1" targetFramework="net40" />
View
102 src/Xbehave.Net45/Guard.cs
@@ -0,0 +1,102 @@
+// <copyright file="Guard.cs" company="xBehave.net contributors">
+// Copyright (c) xBehave.net contributors. All rights reserved.
+// </copyright>
+
+namespace Xbehave
+{
+ using System;
+ using System.Diagnostics;
+ using System.Globalization;
+
+ /// <summary>
+ /// Provides guard clauses.
+ /// </summary>
+ internal static class Guard
+ {
+ /// <summary>
+ /// Guards against a null argument.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgument<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument) where TArgument : class
+ {
+ if (argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument if <typeparamref name="TArgument" /> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentIfNullable<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument)
+ {
+ if (typeof(TArgument).IsNullableType() && argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentProperty<TProperty>(string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ where TProperty : class
+ {
+ if (argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value if <typeparamref name="TProperty"/> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentPropertyIfNullable<TProperty>(
+ string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ {
+ if (typeof(TProperty).IsNullableType() && argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ private static bool IsNullableType(this Type type)
+ {
+ return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
+ }
+
+ // NOTE: when applied to a parameter, this attribute provides an indication to code analysis that the argument has been null checked
+ private sealed class ValidatedNotNullAttribute : Attribute
+ {
+ }
+ }
+}
View
4 src/Xbehave.Net45/Xbehave.Net45.csproj
@@ -49,9 +49,6 @@
<AssemblyOriginatorKeyFile>..\Xbehave.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="LiteGuard">
- <HintPath>..\..\packages\LiteGuard.0.4.0\lib\net35\LiteGuard.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="xunit">
<HintPath>..\..\packages\xunit.2.0.0-alpha-build1611\lib\net45\xunit.dll</HintPath>
@@ -67,6 +64,7 @@
<Compile Include="..\Xbehave.Net40\BackgroundAttribute.cs">
<Link>BackgroundAttribute.cs</Link>
</Compile>
+ <Compile Include="Guard.cs" />
<None Include="..\Xbehave.Net40\Sandbox\DynamicStringExtensions.cs">
<Link>Sandbox\DynamicStringExtensions.cs</Link>
</None>
View
2  src/Xbehave.Net45/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="LiteGuard" version="0.4.0" targetFramework="net45" />
+ <package id="LiteGuard.Source" version="0.5.0" targetFramework="net45" />
<package id="StyleCop.MSBuild" version="4.7.44.1" targetFramework="net45" />
<package id="xunit" version="2.0.0-alpha-build1611" targetFramework="net45" />
<package id="xunit.extensions" version="2.0.0-alpha-build1611" targetFramework="net45" />
View
102 src/Xbehave.Sdk.Net35/Guard.cs
@@ -0,0 +1,102 @@
+// <copyright file="Guard.cs" company="xBehave.net contributors">
+// Copyright (c) xBehave.net contributors. All rights reserved.
+// </copyright>
+
+namespace Xbehave.Sdk
+{
+ using System;
+ using System.Diagnostics;
+ using System.Globalization;
+
+ /// <summary>
+ /// Provides guard clauses.
+ /// </summary>
+ internal static class Guard
+ {
+ /// <summary>
+ /// Guards against a null argument.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgument<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument) where TArgument : class
+ {
+ if (argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument if <typeparamref name="TArgument" /> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentIfNullable<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument)
+ {
+ if (typeof(TArgument).IsNullableType() && argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentProperty<TProperty>(string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ where TProperty : class
+ {
+ if (argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value if <typeparamref name="TProperty"/> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentPropertyIfNullable<TProperty>(
+ string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ {
+ if (typeof(TProperty).IsNullableType() && argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ private static bool IsNullableType(this Type type)
+ {
+ return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
+ }
+
+ // NOTE: when applied to a parameter, this attribute provides an indication to code analysis that the argument has been null checked
+ private sealed class ValidatedNotNullAttribute : Attribute
+ {
+ }
+ }
+}
View
4 src/Xbehave.Sdk.Net35/Xbehave.Sdk.Net35.csproj
@@ -45,9 +45,6 @@
<AssemblyOriginatorKeyFile>..\Xbehave.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="LiteGuard">
- <HintPath>..\..\packages\LiteGuard.0.4.0\lib\net35\LiteGuard.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.XML" />
@@ -107,6 +104,7 @@
<Compile Include="..\Xbehave.Sdk.Net40\TeardownCommand.cs">
<Link>TeardownCommand.cs</Link>
</Compile>
+ <Compile Include="Guard.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\Xbehave.CustomDictionary.xml">
View
2  src/Xbehave.Sdk.Net35/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="LiteGuard" version="0.4.0" targetFramework="net35" />
+ <package id="LiteGuard.Source" version="0.5.0" targetFramework="net35" />
<package id="StyleCop.MSBuild" version="4.7.44.1" targetFramework="net35" />
<package id="xunit" version="1.9.1" targetFramework="net35" />
<package id="xunit.extensions" version="1.9.1" targetFramework="net35" />
View
4 src/Xbehave.Sdk.Net40/Argument.cs
@@ -12,8 +12,8 @@ public class Argument
private readonly bool isGeneratedDefault;
public Argument(Type type)
- {
- LiteGuard.Guard.AgainstNullArgument("type", type);
+ {
+ Guard.AgainstNullArgument("type", type);
this.value = type.IsValueType ? Activator.CreateInstance(type) : null;
this.isGeneratedDefault = true;
View
90 src/Xbehave.Sdk.Net40/Command.cs
@@ -24,8 +24,8 @@ public Command(IMethodInfo method)
public Command(MethodCall methodCall)
: base(methodCall == null ? null : methodCall.Method, null, methodCall == null ? 0 : MethodUtility.GetTimeoutParameter(methodCall.Method))
- {
- LiteGuard.Guard.AgainstNullArgument("methodCall", methodCall);
+ {
+ Guard.AgainstNullArgument("methodCall", methodCall);
this.methodCall = methodCall;
this.arguments = methodCall.Arguments.ToArray();
@@ -38,12 +38,12 @@ public MethodCall MethodCall
get { return this.methodCall; }
}
- // TODO (jamesfoster) make configurable
- protected static bool ShowExampleValues
- {
- get { return false; }
- }
-
+ // TODO (jamesfoster) make configurable
+ protected static bool ShowExampleValues
+ {
+ get { return false; }
+ }
+
public override MethodResult Execute(object testClass)
{
var parameters = testMethod.MethodInfo.GetParameters();
@@ -65,45 +65,45 @@ public override MethodResult Execute(object testClass)
return new PassedResult(testMethod, this.DisplayName);
}
- private static string GetString(IMethodInfo method, Argument[] arguments, Type[] typeArguments)
+ private static string GetString(IMethodInfo method, Argument[] arguments, Type[] typeArguments)
{
- var csharp = string.Concat(method.TypeName, ".", method.Name);
- if (typeArguments.Length > 0)
- {
- csharp = string.Format(
- CultureInfo.InvariantCulture,
- "{0}<{1}>",
- csharp,
- string.Join(", ", typeArguments.Select(typeArgument => GetString(typeArgument)).ToArray()));
- }
-
+ var csharp = string.Concat(method.TypeName, ".", method.Name);
+ if (typeArguments.Length > 0)
+ {
+ csharp = string.Format(
+ CultureInfo.InvariantCulture,
+ "{0}<{1}>",
+ csharp,
+ string.Join(", ", typeArguments.Select(typeArgument => GetString(typeArgument)).ToArray()));
+ }
+
var format = "{0}";
- var parameterTokens = new List<string>();
- if (Command.ShowExampleValues)
- {
- format += "({1})";
-
- var parameters = method.MethodInfo.GetParameters();
- int parameterIndex;
- for (parameterIndex = 0; parameterIndex < arguments.Length; parameterIndex++)
- {
- if (arguments[parameterIndex].IsGeneratedDefault)
- {
- continue;
- }
-
- parameterTokens.Add(string.Concat(
- parameterIndex >= parameters.Length ? "???" : parameters[parameterIndex].Name,
- ": ",
- GetString(arguments[parameterIndex])));
- }
-
- for (; parameterIndex < parameters.Length; parameterIndex++)
- {
- parameterTokens.Add(parameters[parameterIndex].Name + ": ???");
- }
- }
-
+ var parameterTokens = new List<string>();
+ if (Command.ShowExampleValues)
+ {
+ format += "({1})";
+
+ var parameters = method.MethodInfo.GetParameters();
+ int parameterIndex;
+ for (parameterIndex = 0; parameterIndex < arguments.Length; parameterIndex++)
+ {
+ if (arguments[parameterIndex].IsGeneratedDefault)
+ {
+ continue;
+ }
+
+ parameterTokens.Add(string.Concat(
+ parameterIndex >= parameters.Length ? "???" : parameters[parameterIndex].Name,
+ ": ",
+ GetString(arguments[parameterIndex])));
+ }
+
+ for (; parameterIndex < parameters.Length; parameterIndex++)
+ {
+ parameterTokens.Add(parameters[parameterIndex].Name + ": ???");
+ }
+ }
+
return string.Format(CultureInfo.InvariantCulture, format, csharp, string.Join(", ", parameterTokens.ToArray()));
}
View
2  src/Xbehave.Sdk.Net40/Context.cs
@@ -19,7 +19,7 @@ public class Context
public Context(MethodCall methodCall, IEnumerable<Step> steps)
{
- LiteGuard.Guard.AgainstNullArgument("steps", steps);
+ Guard.AgainstNullArgument("steps", steps);
this.methodCall = methodCall;
this.steps = steps.ToArray();
View
2  src/Xbehave.Sdk.Net40/ContextFactory.cs
@@ -13,7 +13,7 @@ public class ContextFactory
{
public IEnumerable<Context> CreateContexts(MethodCall methodCall, IEnumerable<Step> steps)
{
- LiteGuard.Guard.AgainstNullArgument("steps", steps);
+ Guard.AgainstNullArgument("steps", steps);
var sharedContext = new List<Step>();
var pendingYield = false;
View
4 src/Xbehave.Sdk.Net40/CurrentScenario.cs
@@ -70,8 +70,8 @@ public static IEnumerable<Action> ExtractTeardowns()
Justification = "Required to prevent infinite loops in test runners (TestDrive.NET, Resharper) when they are allowed to handle exceptions.")]
public static IEnumerable<ITestCommand> ExtractCommands(MethodCall methodCall, IEnumerable<ITestCommand> commands)
{
- LiteGuard.Guard.AgainstNullArgument("methodCall", methodCall);
- LiteGuard.Guard.AgainstNullArgument("commands", commands);
+ Guard.AgainstNullArgument("methodCall", methodCall);
+ Guard.AgainstNullArgument("commands", commands);
try
{
View
102 src/Xbehave.Sdk.Net40/Guard.cs
@@ -0,0 +1,102 @@
+// <copyright file="Guard.cs" company="xBehave.net contributors">
+// Copyright (c) xBehave.net contributors. All rights reserved.
+// </copyright>
+
+namespace Xbehave.Sdk
+{
+ using System;
+ using System.Diagnostics;
+ using System.Globalization;
+
+ /// <summary>
+ /// Provides guard clauses.
+ /// </summary>
+ internal static class Guard
+ {
+ /// <summary>
+ /// Guards against a null argument.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgument<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument) where TArgument : class
+ {
+ if (argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument if <typeparamref name="TArgument" /> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentIfNullable<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument)
+ {
+ if (typeof(TArgument).IsNullableType() && argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentProperty<TProperty>(string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ where TProperty : class
+ {
+ if (argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value if <typeparamref name="TProperty"/> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentPropertyIfNullable<TProperty>(
+ string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ {
+ if (typeof(TProperty).IsNullableType() && argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ private static bool IsNullableType(this Type type)
+ {
+ return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
+ }
+
+ // NOTE: when applied to a parameter, this attribute provides an indication to code analysis that the argument has been null checked
+ private sealed class ValidatedNotNullAttribute : Attribute
+ {
+ }
+ }
+}
View
2  src/Xbehave.Sdk.Net40/Step.cs
@@ -17,7 +17,7 @@ public class Step
public Step(string name, Action body)
{
- LiteGuard.Guard.AgainstNullArgument("body", body);
+ Guard.AgainstNullArgument("body", body);
this.name = name;
this.body = body;
View
4 src/Xbehave.Sdk.Net40/StepCommand.cs
@@ -17,8 +17,8 @@ public class StepCommand : ContextCommand
public StepCommand(MethodCall methodCall, int contextOrdinal, int stepOrdinal, Step step)
: base(methodCall, contextOrdinal, stepOrdinal)
{
- LiteGuard.Guard.AgainstNullArgument("methodCall", methodCall);
- LiteGuard.Guard.AgainstNullArgument("step", step);
+ Guard.AgainstNullArgument("methodCall", methodCall);
+ Guard.AgainstNullArgument("step", step);
if (step.Name == null)
{
View
2  src/Xbehave.Sdk.Net40/TeardownCommand.cs
@@ -19,7 +19,7 @@ public class TeardownCommand : ContextCommand
public TeardownCommand(MethodCall methodCall, int contextOrdinal, int stepOrdinal, IEnumerable<Action> teardowns)
: base(methodCall, contextOrdinal, stepOrdinal)
{
- LiteGuard.Guard.AgainstNullArgument("teardowns", teardowns);
+ Guard.AgainstNullArgument("teardowns", teardowns);
this.teardowns = teardowns.ToArray();
this.Name = string.Format(CultureInfo.InvariantCulture, "{0} {1}", this.Name, "(Teardown)");
View
4 src/Xbehave.Sdk.Net40/Xbehave.Sdk.Net40.csproj
@@ -45,9 +45,6 @@
<AssemblyOriginatorKeyFile>..\Xbehave.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="LiteGuard">
- <HintPath>..\..\packages\LiteGuard.0.4.0\lib\net35\LiteGuard.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.XML" />
@@ -65,6 +62,7 @@
<Compile Include="Argument.cs" />
<Compile Include="ContextCommand.cs" />
<Compile Include="BackgroundCommand.cs" />
+ <Compile Include="Guard.cs" />
<Compile Include="MethodCall.cs" />
<Compile Include="ICommand.cs" />
<Compile Include="ReplayCommand.cs" />
View
2  src/Xbehave.Sdk.Net40/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="LiteGuard" version="0.4.0" targetFramework="net40" />
+ <package id="LiteGuard.Source" version="0.5.0" targetFramework="net40" />
<package id="StyleCop.MSBuild" version="4.7.44.1" targetFramework="net40" />
<package id="xunit" version="1.9.1" targetFramework="net40" />
<package id="xunit.extensions" version="1.9.1" targetFramework="net40" />
View
102 src/Xbehave.Sdk.Net45/Guard.cs
@@ -0,0 +1,102 @@
+// <copyright file="Guard.cs" company="xBehave.net contributors">
+// Copyright (c) xBehave.net contributors. All rights reserved.
+// </copyright>
+
+namespace Xbehave.Sdk
+{
+ using System;
+ using System.Diagnostics;
+ using System.Globalization;
+
+ /// <summary>
+ /// Provides guard clauses.
+ /// </summary>
+ internal static class Guard
+ {
+ /// <summary>
+ /// Guards against a null argument.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TArgument"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgument<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument) where TArgument : class
+ {
+ if (argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument if <typeparamref name="TArgument" /> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TArgument">The type of the argument.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="argument">The argument.</param>
+ /// <exception cref="System.ArgumentNullException"><paramref name="argument" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentIfNullable<TArgument>(string parameterName, [ValidatedNotNull]TArgument argument)
+ {
+ if (typeof(TArgument).IsNullableType() && argument == null)
+ {
+ throw new ArgumentNullException(parameterName, string.Format(CultureInfo.InvariantCulture, "{0} is null.", parameterName));
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks><typeparamref name="TProperty"/> is restricted to reference types to avoid boxing of value type objects.</remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentProperty<TProperty>(string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ where TProperty : class
+ {
+ if (argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ /// <summary>
+ /// Guards against a null argument property value if <typeparamref name="TProperty"/> can be <c>null</c>.
+ /// </summary>
+ /// <typeparam name="TProperty">The type of the property.</typeparam>
+ /// <param name="parameterName">Name of the parameter.</param>
+ /// <param name="propertyName">Name of the property.</param>
+ /// <param name="argumentProperty">The argument property.</param>
+ /// <exception cref="System.ArgumentException"><paramref name="argumentProperty" /> is <c>null</c>.</exception>
+ /// <remarks>
+ /// Performs a type check to avoid boxing of value type objects.
+ /// </remarks>
+ [DebuggerStepThrough]
+ public static void AgainstNullArgumentPropertyIfNullable<TProperty>(
+ string parameterName, string propertyName, [ValidatedNotNull]TProperty argumentProperty)
+ {
+ if (typeof(TProperty).IsNullableType() && argumentProperty == null)
+ {
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "{0}.{1} is null.", parameterName, propertyName), parameterName);
+ }
+ }
+
+ private static bool IsNullableType(this Type type)
+ {
+ return !type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>));
+ }
+
+ // NOTE: when applied to a parameter, this attribute provides an indication to code analysis that the argument has been null checked
+ private sealed class ValidatedNotNullAttribute : Attribute
+ {
+ }
+ }
+}
View
4 src/Xbehave.Sdk.Net45/Xbehave.Sdk.Net45.csproj
@@ -48,9 +48,6 @@
<AssemblyOriginatorKeyFile>..\Xbehave.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="LiteGuard">
- <HintPath>..\..\packages\LiteGuard.0.4.0\lib\net35\LiteGuard.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.XML" />
@@ -112,6 +109,7 @@
<Compile Include="..\Xbehave.Sdk.Net40\TeardownCommand.cs">
<Link>TeardownCommand.cs</Link>
</Compile>
+ <Compile Include="Guard.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\Xbehave.CustomDictionary.xml">
View
2  src/Xbehave.Sdk.Net45/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="LiteGuard" version="0.4.0" targetFramework="net45" />
+ <package id="LiteGuard.Source" version="0.5.0" targetFramework="net45" />
<package id="StyleCop.MSBuild" version="4.7.44.1" targetFramework="net45" />
<package id="xunit" version="2.0.0-alpha-build1611" targetFramework="net45" />
<package id="xunit.extensions" version="2.0.0-alpha-build1611" targetFramework="net45" />
View
2  src/Xbehave.Windows_NT.nuspec
@@ -14,12 +14,10 @@
<tags>xUnit.net BDD test TDD</tags>
<dependencies>
<group targetFramework="net35">
- <dependency id="LiteGuard" />
<dependency id="xunit" version="[1.9.1]" />
<dependency id="xunit.extensions" version="[1.9.1]" />
</group>
<group targetFramework="net40">
- <dependency id="LiteGuard" />
<dependency id="xunit" version="[1.9.1]" />
<dependency id="xunit.extensions" version="[1.9.1]" />
</group>
View
2  src/Xbehave.nuspec
@@ -14,12 +14,10 @@
<tags>xUnit.net BDD test TDD</tags>
<dependencies>
<group targetFramework="net35">
- <dependency id="LiteGuard" />
<dependency id="xunit" version="[1.9.1]" />
<dependency id="xunit.extensions" version="[1.9.1]" />
</group>
<group targetFramework="net40">
- <dependency id="LiteGuard" />
<dependency id="xunit" version="[1.9.1]" />
<dependency id="xunit.extensions" version="[1.9.1]" />
</group>
Please sign in to comment.
Something went wrong with that request. Please try again.