Skip to content

Commit

Permalink
Convert to auto-implemented getter-only properties (pt. 11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Mar 16, 2016
1 parent 5de1a83 commit 95f5da8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 105 deletions.
29 changes: 10 additions & 19 deletions Src/AutoFixture/Kernel/PropertyTypeAndNameCriterion.cs
Expand Up @@ -21,9 +21,6 @@ namespace Ploeh.AutoFixture.Kernel
/// <seealso cref="FieldTypeAndNameCriterion" />
public class PropertyTypeAndNameCriterion : IEquatable<PropertyInfo>
{
private readonly IEquatable<Type> typeCriterion;
private readonly IEquatable<string> nameCriterion;

/// <summary>
/// Initializes a new instance of the
/// <see cref="PropertyTypeAndNameCriterion" /> class with the desired
Expand All @@ -48,8 +45,8 @@ public class PropertyTypeAndNameCriterion : IEquatable<PropertyInfo>
if (nameCriterion == null)
throw new ArgumentNullException(nameof(nameCriterion));

this.typeCriterion = typeCriterion;
this.nameCriterion = nameCriterion;
this.TypeCriterion = typeCriterion;
this.NameCriterion = nameCriterion;
}

/// <summary>
Expand Down Expand Up @@ -77,8 +74,8 @@ public bool Equals(PropertyInfo other)
if (other == null)
return false;

return this.typeCriterion.Equals(other.PropertyType)
&& this.nameCriterion.Equals(other.Name);
return this.TypeCriterion.Equals(other.PropertyType)
&& this.NameCriterion.Equals(other.Name);
}

/// <summary>
Expand All @@ -95,25 +92,19 @@ public override bool Equals(object obj)
if (other == null)
return base.Equals(obj);

return object.Equals(this.typeCriterion, other.typeCriterion)
&& object.Equals(this.nameCriterion, other.nameCriterion);
return object.Equals(this.TypeCriterion, other.TypeCriterion)
&& object.Equals(this.NameCriterion, other.NameCriterion);
}

/// <summary>
/// The type criterion originally passed in via the class' constructor.
/// </summary>
public IEquatable<Type> TypeCriterion
{
get { return this.typeCriterion; }
}
public IEquatable<Type> TypeCriterion { get; }

/// <summary>
/// The name criterion originally passed in via the class' constructor.
/// </summary>
public IEquatable<string> NameCriterion
{
get { return this.nameCriterion; }
}
public IEquatable<string> NameCriterion { get; }

/// <summary>
/// Returns the hash code for the object.
Expand All @@ -122,8 +113,8 @@ public IEquatable<string> NameCriterion
public override int GetHashCode()
{
return
this.typeCriterion.GetHashCode() ^
this.nameCriterion.GetHashCode();
this.TypeCriterion.GetHashCode() ^
this.NameCriterion.GetHashCode();
}
}
}
34 changes: 6 additions & 28 deletions Src/AutoFixture/Kernel/RangedNumberRequest.cs
Expand Up @@ -8,10 +8,6 @@ namespace Ploeh.AutoFixture.Kernel
/// </summary>
public class RangedNumberRequest : IEquatable<RangedNumberRequest>
{
private readonly Type operandType;
private readonly object minimum;
private readonly object maximum;

/// <summary>
/// Initializes a new instance of the <see cref="RangedNumberRequest"/> class.
/// </summary>
Expand Down Expand Up @@ -40,9 +36,9 @@ public RangedNumberRequest(Type operandType, object minimum, object maximum)
throw new ArgumentOutOfRangeException(nameof(minimum), "Minimum must be lower than Maximum.");
}

this.operandType = operandType;
this.minimum = minimum;
this.maximum = maximum;
this.OperandType = operandType;
this.Minimum = minimum;
this.Maximum = maximum;
}

/// <summary>
Expand All @@ -51,35 +47,17 @@ public RangedNumberRequest(Type operandType, object minimum, object maximum)
/// <value>
/// The type of the operand.
/// </value>
public Type OperandType
{
get
{
return this.operandType;
}
}
public Type OperandType { get; }

/// <summary>
/// Gets the minimum value.
/// </summary>
public object Minimum
{
get
{
return this.minimum;
}
}
public object Minimum { get; }

/// <summary>
/// Gets the maximum value.
/// </summary>
public object Maximum
{
get
{
return this.maximum;
}
}
public object Maximum { get; }

/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
Expand Down
52 changes: 17 additions & 35 deletions Src/AutoFixture/Kernel/RecursionGuard.cs
Expand Up @@ -14,10 +14,6 @@ namespace Ploeh.AutoFixture.Kernel
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "The main responsibility of this class isn't to be a 'collection' (which, by the way, it isn't - it's just an Iterator).")]
public class RecursionGuard : ISpecimenBuilderNode
{
private readonly ISpecimenBuilder builder;
private readonly IRecursionHandler recursionHandler;
private readonly IEqualityComparer comparer;

private readonly ConcurrentDictionary<Thread, Stack<object>>
_requestsByThread = new ConcurrentDictionary<Thread, Stack<object>>();

Expand All @@ -26,8 +22,6 @@ private Stack<object> GetMonitoredRequestsForCurrentThread()
return _requestsByThread.GetOrAdd(Thread.CurrentThread, _ => new Stack<object>());
}

private readonly int recursionDepth;

/// <summary>
/// Initializes a new instance of the <see cref="RecursionGuard"/> class.
/// </summary>
Expand Down Expand Up @@ -100,9 +94,9 @@ public RecursionGuard(ISpecimenBuilder builder, IEqualityComparer comparer)
throw new ArgumentNullException(nameof(comparer));
}

this.builder = builder;
this.comparer = comparer;
this.recursionDepth = 1;
this.Builder = builder;
this.Comparer = comparer;
this.RecursionDepth = 1;
}

/// <summary>
Expand Down Expand Up @@ -177,21 +171,18 @@ public RecursionGuard(ISpecimenBuilder builder, IEqualityComparer comparer)
if (recursionDepth < 1)
throw new ArgumentOutOfRangeException(nameof(recursionDepth), "Recursion depth must be greater than 0.");

this.builder = builder;
this.recursionHandler = recursionHandler;
this.comparer = comparer;
this.recursionDepth = recursionDepth;
this.Builder = builder;
this.RecursionHandler = recursionHandler;
this.Comparer = comparer;
this.RecursionDepth = recursionDepth;
}

/// <summary>
/// Gets the decorated builder supplied via the constructor.
/// </summary>
/// <seealso cref="RecursionGuard(ISpecimenBuilder)"/>
/// <seealso cref="RecursionGuard(ISpecimenBuilder, IEqualityComparer)" />
public ISpecimenBuilder Builder
{
get { return this.builder; }
}
public ISpecimenBuilder Builder { get; }

/// <summary>
/// Gets the recursion handler originally supplied as a constructor
Expand All @@ -202,26 +193,17 @@ public ISpecimenBuilder Builder
/// </value>
/// <seealso cref="RecursionGuard(ISpecimenBuilder, IRecursionHandler)" />
/// <seealso cref="RecursionGuard(ISpecimenBuilder, IRecursionHandler, IEqualityComparer)" />
public IRecursionHandler RecursionHandler
{
get { return this.recursionHandler; }
}
public IRecursionHandler RecursionHandler { get; }

/// <summary>
/// The recursion depth at which the request will be treated as a
/// recursive request
/// </summary>
public int RecursionDepth
{
get { return recursionDepth; }
}
public int RecursionDepth { get; }

/// <summary>Gets the comparer supplied via the constructor.</summary>
/// <seealso cref="RecursionGuard(ISpecimenBuilder, IEqualityComparer)" />
public IEqualityComparer Comparer
{
get { return this.comparer; }
}
public IEqualityComparer Comparer { get; }

/// <summary>
/// Gets the recorded requests so far.
Expand All @@ -239,7 +221,7 @@ protected IEnumerable RecordedRequests
[Obsolete("This method will be removed in a future version of AutoFixture. Use IRecursionHandler.HandleRecursiveRequest instead.")]
public virtual object HandleRecursiveRequest(object request)
{
return this.recursionHandler.HandleRecursiveRequest(
return this.RecursionHandler.HandleRecursiveRequest(
request,
GetMonitoredRequestsForCurrentThread());
}
Expand Down Expand Up @@ -270,7 +252,7 @@ public object Create(object request, ISpecimenContext context)
for (int i = 0; i < requestsArray.Length; i++)
{
var existingRequest = requestsArray[i];
if (this.comparer.Equals(existingRequest, request))
if (this.Comparer.Equals(existingRequest, request))
{
numRequestsSameAsThisOne++;
}
Expand All @@ -287,7 +269,7 @@ public object Create(object request, ISpecimenContext context)
requestsForCurrentThread.Push(request);
try
{
return this.builder.Create(request, context);
return this.Builder.Create(request, context);
}
finally
{
Expand Down Expand Up @@ -325,8 +307,8 @@ public object Create(object request, ISpecimenContext context)
builders);
return new RecursionGuard(
composedBuilder,
this.recursionHandler,
this.comparer,
this.RecursionHandler,
this.Comparer,
this.RecursionDepth);
}

Expand All @@ -339,7 +321,7 @@ public object Create(object request, ISpecimenContext context)
/// </returns>
public virtual IEnumerator<ISpecimenBuilder> GetEnumerator()
{
yield return this.builder;
yield return this.Builder;
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down
12 changes: 2 additions & 10 deletions Src/AutoFixture/Kernel/RegularExpressionRequest.cs
Expand Up @@ -7,8 +7,6 @@ namespace Ploeh.AutoFixture.Kernel
/// </summary>
public class RegularExpressionRequest : IEquatable<RegularExpressionRequest>
{
private readonly string pattern;

/// <summary>
/// Initializes a new instance of the <see cref="RegularExpressionRequest"/> class.
/// </summary>
Expand All @@ -20,19 +18,13 @@ public RegularExpressionRequest(string pattern)
throw new ArgumentNullException(nameof(pattern));
}

this.pattern = pattern;
this.Pattern = pattern;
}

/// <summary>
/// Gets the regular expression pattern.
/// </summary>
public string Pattern
{
get
{
return this.pattern;
}
}
public string Pattern { get; }

/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
Expand Down
17 changes: 4 additions & 13 deletions Src/AutoFixture/Kernel/RequestTraceEventArgs.cs
Expand Up @@ -7,9 +7,6 @@ namespace Ploeh.AutoFixture.Kernel
/// </summary>
public class RequestTraceEventArgs : EventArgs
{
private readonly object request;
private readonly int depth;

/// <summary>
/// Initializes a new instance of the <see cref="RequestTraceEventArgs"/> class with the
/// supplied values.
Expand All @@ -20,24 +17,18 @@ public class RequestTraceEventArgs : EventArgs
/// </param>
public RequestTraceEventArgs(object request, int depth)
{
this.request = request;
this.depth = depth;
this.Request = request;
this.Depth = depth;
}

/// <summary>
/// Gets the recursion depth at which <see cref="Request"/> occurred.
/// </summary>
public int Depth
{
get { return this.depth; }
}
public int Depth { get; }

/// <summary>
/// Gets the original request for a specimen
/// </summary>
public object Request
{
get { return this.request; }
}
public object Request { get; }
}
}

0 comments on commit 95f5da8

Please sign in to comment.