Skip to content

Commit

Permalink
refactor: remove InputBox-based editors
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavisau committed Sep 28, 2019
1 parent ff9897f commit 1970020
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 78 deletions.
4 changes: 0 additions & 4 deletions src/DumpEditable/DumpEditable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
</ItemGroup>

</Project>
74 changes: 0 additions & 74 deletions src/DumpEditable/Editors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ public static partial class Editors
public static Func<EditorRule.ParseFunc<string, object, bool>, bool, bool, Func<object, PropertyInfo, Func<object>, Action<object>, object>> TextBoxBasedStringEditor
(bool liveUpdates) => (parse, nullable, enumerable) => (o, p, gv, sv) =>
Editors.StringWithTextBox(o, p, gv, sv, parse, nullable, enumerable, liveUpdates);

public static Func<EditorRule.ParseFunc<string, object, bool>, bool, bool, Func<object, PropertyInfo, Func<object>, Action<object>, object>> InputBoxBasedStringEditor
=> (parse, nullable, enumerable) => (o, p, gv, sv) =>
Editors.StringWithInputBox(o, p, gv, sv, parse, nullable, enumerable);

internal static object StringWithTextBox<TOut>(object o, PropertyInfo p, Func<object> gv, Action<object> sv,
EditorRule.ParseFunc<string, TOut, bool> parseFunc,
Expand Down Expand Up @@ -226,76 +222,6 @@ bool TryGetParsedValue(string str, out object @out)

return dc;
}

internal static object StringWithInputBox<TOut>(object o, PropertyInfo p, Func<object> getCurrValue, Action<object> setNewValue, EditorRule.ParseFunc<string, TOut, bool> parseFunc,
bool supportNullable = true, bool supportEnumerable = true)
{
var type = p.PropertyType;
var isEnumerable = supportEnumerable && type.GetArrayLikeElementType() != null;

// handle string which is IEnumerable<char>
if (type == typeof(string) && type.GetArrayLikeElementType() == typeof(char))
isEnumerable = false;

string GetStringDescription()
{
var currVal = getCurrValue();
var val = currVal == null
? NullString
: (isEnumerable ? JsonConvert.SerializeObject(currVal) : $"{currVal}");

// hyperlinq doesn't like empty strings
if (val == String.Empty)
val = EmptyString;

return val;
}

var dc = new DumpContainer();

Hyperlinq Update()
{
var desc = GetStringDescription();

return new Hyperlinq(() =>
{
var newVal = Interaction.InputBox("Set value for " + p.Name, p.Name,
desc != EmptyString ? desc : String.Empty);
var canConvert = parseFunc(newVal, out var output);
if (isEnumerable)
{
try
{
var val = JsonConvert.DeserializeObject(newVal, type);
setNewValue(val);
dc.Content = Update();
}
catch
{
return; // can't deserialise
}
}
else if (canConvert)
{
setNewValue(output);
dc.Content = Update();
}
else if (supportNullable && (newVal == String.Empty))
{
setNewValue(null);
dc.Content = Update();
}
else
return; // can't convert
}, desc);
}

dc.Content = Update();

return Util.HorizontalRun(true, dc);
}

public const string NullString = "(null)";
public const string EmptyString = "(empty string)";
Expand Down

0 comments on commit 1970020

Please sign in to comment.