Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2034 from felipeleusin/debugger_friendly_context
Browse files Browse the repository at this point in the history
Debugger friendly context
  • Loading branch information
thecodejunkie committed Sep 7, 2015
2 parents 6b7ddcc + 02f3d95 commit 97b40c6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Nancy/DynamicDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Text;

/// <summary>
/// A dictionary that supports dynamic access.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay, nq}")]
public class DynamicDictionary : DynamicObject, IEquatable<DynamicDictionary>, IHideObjectMembers, IEnumerable<string>, IDictionary<string, object>
{
private readonly IDictionary<string, dynamic> dictionary =
Expand Down Expand Up @@ -343,5 +347,32 @@ public Dictionary<string, object> ToDictionary()

return data;
}

private string DebuggerDisplay
{
get
{
var builder = new StringBuilder();
var maxItems = Math.Min(this.dictionary.Count, 5);

builder.Append("{");

for (var i = 0; i < maxItems; i++)
{
var item = this.dictionary.ElementAt(i);

builder.AppendFormat(" {0} = {1}{2}", item.Key, item.Value, i < maxItems - 1 ? "," : string.Empty);
}

if (maxItems < this.dictionary.Count)
{
builder.Append("...");
}

builder.Append(" }");

return builder.ToString();
}
}
}
}
7 changes: 7 additions & 0 deletions src/Nancy/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Nancy
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
Expand All @@ -15,6 +16,7 @@ namespace Nancy
/// <summary>
/// Encapsulates HTTP-request information to an Nancy application.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay, nq}")]
public class Request : IDisposable
{
private readonly List<HttpFile> files = new List<HttpFile>();
Expand Down Expand Up @@ -316,5 +318,10 @@ private void RewriteMethod()

this.Method = providedOverride.Single().Item2;
}

private string DebuggerDisplay
{
get { return string.Format("{0} {1} {2}", this.Method, this.Url, this.ProtocolVersion).Trim(); }
}
}
}
7 changes: 7 additions & 0 deletions src/Nancy/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace Nancy
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -13,6 +14,7 @@ namespace Nancy
/// <summary>
/// Encapsulates HTTP-response information from an Nancy operation.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay, nq}")]
public class Response: IDisposable
{
/// <summary>
Expand Down Expand Up @@ -215,5 +217,10 @@ protected static Action<Stream> GetStringContents(string contents)
public virtual void Dispose()
{
}

private string DebuggerDisplay
{
get { return string.Join(" ", new string[] { this.StatusCode.ToString(), this.ReasonPhrase, this.ContentType }.Where(x => !string.IsNullOrEmpty(x)).ToArray()); }
}
}
}
2 changes: 2 additions & 0 deletions src/Nancy/Routing/Route.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
namespace Nancy.Routing
{
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

/// <summary>
/// Stores information about a declared route in Nancy.
/// </summary>
[DebuggerDisplay("{Description.DebuggerDisplay, nq}")]
public class Route
{
/// <summary>
Expand Down
21 changes: 21 additions & 0 deletions src/Nancy/Routing/RouteDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ namespace Nancy.Routing
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

/// <summary>
/// Represents the various parts of a route lambda.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay, nq}")]
public sealed class RouteDescription
{
/// <summary>
Expand Down Expand Up @@ -73,5 +77,22 @@ public RouteDescription(string name, string method, string path, Func<NancyConte
/// </summary>
/// <value>An <see cref="IEnumerable{T}"/>, containing the segments for the route.</value>
public IEnumerable<string> Segments { get; set; }

private string DebuggerDisplay
{
get
{
var builder = new StringBuilder();

if (!string.IsNullOrEmpty(this.Name))
{
builder.AppendFormat("{0} - ", this.Name);
}

builder.AppendFormat("{0} {1}", this.Method, this.Path);

return builder.ToString();
}
}
}
}
2 changes: 2 additions & 0 deletions src/Nancy/Validation/ModelValidationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

/// <summary>
/// Represents the result of a model validation.
/// </summary>
[DebuggerDisplay("IsValid = {IsValid}")]
public class ModelValidationResult
{
/// <summary>
Expand Down

0 comments on commit 97b40c6

Please sign in to comment.