Open lust4life opened 6 years ago
an object with default destructuring is rendered as a string literal
Is this still true even with support custom format ?
Hi @lust4life sorry I haven't got to this yet, I'll try to look in the next few days :+1: Thanks!
@adamchester 😃 , ok , take your time. i will ping you after few days.
@adamchester do we need consider replace "\n"
with "\\n"
, when write as string ? right now , we just deal with "
. if we also deal with newline, in most case, the output can be just one line string.
type User =
{
id : int
name : string
created : DateTime
}
let foo = { id = 999; name = "foo"; created = DateTime.Now}
Formatting.format (Parser.parse "stringify is: {$foo} and destructure is: {@capture}") [| foo; foo |]
right now:
val it : string =
"stringify is: "{id = 999;
name = \"foo\";
created = 11/18/2017 2:37:46 PM;}" and destructure is: User { id: 999, name: "foo", created: 11/18/2017 2:37:46 PM }"
replaced:
val it : string =
"stringify is: "{id = 999;\n name = \"foo\";\n created = 11/18/2017 2:43:30 PM;}" and destructure is: User { id: 999, name: "foo", created: 11/18/2017 2:43:30 PM }"
if user want to keep newline as it was, they can add l
as its format.
Formatting.format (Parser.parse "stringify is: {$foo:l} and destructure is: {@capture}") [| foo; foo |]
val it : string =
"stringify is: {id = 999;
name = "foo";
created = 11/18/2017 2:37:46 PM;} and destructure is: User { id: 999, name: "foo", created: 11/18/2017 2:37:46 PM }"
after that, things become as:
$
means capture as string (Forcing Stringification), just invoke obj.ToString()
, neither ICustomFormatter
nor IFormattable
will be involved, and this will handle with "
and newline
.ICustomFormatter
or IFormattable
.Hey @lust4life!
do we need consider replace "\n" with "\n" , when write as string ?
Can you please elaborate on why replacing newlines would be better?
want to use messagetemplates to format Event
message in Logary (maybe next version), seems levelDatetimeMessagePathNewLine
did not want to show some newline in message template (the body part), one line will be more conducive to the format unification.
But it's not necessary, it's just a temporary thought and can be done in logary itself. What i really want here is: change scalarStringCatchAllDestr
to catch the original scalar object, this will support custom format.
and should we support Map here isScalarDict ?
Change
scalarStringCatchAllDestr
to catch the original scalar object, then format properly whenwritePropValue
.e.g.
before:
after: