Skip to content

Commit

Permalink
DebuggerDisplay for Option<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Dec 23, 2016
1 parent c9b9959 commit f4668ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Optional/Option_Maybe.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

Expand All @@ -12,6 +13,7 @@ namespace Optional
#if !NETSTANDARD
[Serializable]
#endif
[DebuggerDisplay("{" + nameof(DebugString) + "}")]
public struct Option<T> : IEquatable<Option<T>>
{
private readonly bool hasValue;
Expand Down Expand Up @@ -91,6 +93,24 @@ public override int GetHashCode()
return 0;
}

string DebugString
{
get
{
if (hasValue)
{
if (value == null)
{
return "Some(null)";
}

return string.Format("Some({0})", value);
}

return "None";
}
}

/// <summary>
/// Returns a string that represents the current optional.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Portable.Optional/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"Microsoft.NETCore.Platforms": "1.0.1",
"System.Collections": "4.0.11"
"System.Collections": "4.0.11",
"System.Diagnostics.Debug": "4.0.11"
},
"frameworks": {
"netstandard1.0": {}
Expand Down

0 comments on commit f4668ce

Please sign in to comment.