Skip to content

Commit

Permalink
feat: add preliminary expansion support
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavisau committed Apr 26, 2019
1 parent 346c4fd commit 7da1585
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/DumpEditable/EditableDumpContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public static void AddGlobalEditorRule(EditorRule rule)
EditorRule.ForTypeWithStringBasedEditor<byte>(byte.TryParse),
EditorRule.ForTypeWithStringBasedEditor<sbyte>(sbyte.TryParse),
EditorRule.ForTypeWithStringBasedEditor<char>(char.TryParse),
EditorRule.ForExpansionAttribute(),
EditorRule.ForNestedAnonymousType()
};

}
Expand Down
23 changes: 23 additions & 0 deletions src/DumpEditable/EditorRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using LINQPad.DumpEditable.Helpers;
using LINQPad.DumpEditable.Models;
using Microsoft.VisualBasic;
using Newtonsoft.Json;

Expand Down Expand Up @@ -31,6 +32,28 @@ public static EditorRule ForType<T>(Func<object, PropertyInfo, Func<object>, Act
Editor = getEditor,
};

public static EditorRule ForExpansionAttribute()
=> EditorRule.For(
(_, p) => p.GetCustomAttributes<DumpEditableExpandAttribute>().Any(),
(o, p, get, set) =>
{
var v = get();
var editor = EditableDumpContainer.For(v);
editor.OnChanged += () => set(v);
return editor;
});

public static EditorRule ForNestedAnonymousType()
=> EditorRule.For(
(_, p) => p.PropertyType.IsAnonymousType(),
(o, p, get, set) =>
{
var v = get();
var editor = EditableDumpContainer.For(v);
editor.OnChanged += () => set(v);
return editor;
});

public static EditorRule ForEnums() =>
EditorRule.For(
(_, p) => p.PropertyType.IsEnum,
Expand Down
12 changes: 12 additions & 0 deletions src/DumpEditable/Models/DumpEditableExpandAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LINQPad.DumpEditable.Models
{
public class DumpEditableExpandAttribute : Attribute
{
}
}

0 comments on commit 7da1585

Please sign in to comment.