Skip to content

Commit

Permalink
Adding CharQuotationChar and QuoteCharValues
Browse files Browse the repository at this point in the history
  • Loading branch information
MoaidHathot committed Dec 30, 2023
1 parent 0118cd5 commit 336d377
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Dumpify.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
void TestSpecific()
{
'a'.Dump();
Enumerable.Range(0, 10).Select(i => (char)(i + 'a')).Dump();
Enumerable.Range(0, 10).Select(i => (char)(i + 'a')).ToArray().Dump();
"this is a string".Dump();
//new TestVirtual().Dump();
// DumpConfig.Default.TypeRenderingConfig.StringQuotationChar = '`';
//
Expand Down
2 changes: 2 additions & 0 deletions src/Dumpify/Config/TypeRenderingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public class TypeRenderingConfig
{
public bool QuoteStringValues { get; set; } = true;
public char StringQuotationChar { get; set; } = '"';
public bool QuoteCharValues { get; set; } = true;
public char CharQuotationChar { get; set; } = '\'';
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ protected virtual IRenderable RenderSingleValue(object value, RenderContext<Spec

protected override IRenderable RenderSingleValueDescriptor(object obj, SingleValueDescriptor descriptor, RenderContext<SpectreRendererState> context)
{
var quotationChar = context.Config.TypeRenderingConfig.StringQuotationChar;
var stringQuotationChar = context.Config.TypeRenderingConfig.StringQuotationChar;
var charQuotationChar = context.Config.TypeRenderingConfig.CharQuotationChar;
var renderValue = obj switch
{
string str when context.Config.TypeRenderingConfig.QuoteStringValues => $"{quotationChar}{str}{quotationChar}",
string str when context.Config.TypeRenderingConfig.QuoteStringValues => $"{stringQuotationChar}{str}{stringQuotationChar}",
char ch when context.Config.TypeRenderingConfig.QuoteCharValues => $"{charQuotationChar}{ch}{charQuotationChar}",
_ => obj,
};

Expand Down

0 comments on commit 336d377

Please sign in to comment.