Skip to content

Take advantage of ICustomFormatter or IFormattable when an object with default destructuring #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/FsMessageTemplates/MessageTemplates.fs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ module Destructure =
match r.Hint with | DestrHint.Stringify -> ScalarValue (r.Value.ToString()) | _ -> TemplatePropertyValue.Empty

let inline tryDelegateString (r:DestructureRequest) =
if r.Hint <> DestrHint.Destructure then TemplatePropertyValue.Empty
if r.Hint = DestrHint.Destructure then TemplatePropertyValue.Empty
else
match tryCastAs<System.Delegate>(r.Value) with
| e when (Object.ReferenceEquals(null, e)) -> TemplatePropertyValue.Empty
Expand Down Expand Up @@ -490,7 +490,7 @@ module Destructure =
DictionaryValue skvps
| e -> SequenceValue(e |> Seq.cast<obj> |> Seq.map r.TryAgainWithValue |> Seq.toList)

let inline scalarStringCatchAllDestr (r:DestructureRequest) = ScalarValue (r.Value.ToString())
let inline scalarOriginCatchAllDestr (r:DestructureRequest) = ScalarValue (r.Value)

let inline isPublicInstanceReadProp (p:PropertyInfo) =
p.CanRead && p.GetMethod.IsPublic && not (p.GetMethod.IsStatic) &&
Expand Down Expand Up @@ -534,7 +534,7 @@ module Destructure =
let inline alwaysKeepTrying (_:DestructureRequest) = TemplatePropertyValue.Empty

/// Attempts all built-in destructurers in the correct order, falling
/// back to 'scalarStringCatchAllDestr' (stringify) if no better option
/// back to 'scalarOriginCatchAllDestr' (origin) if no better option
/// is found first. Also supports custom scalars and custom object
/// destructuring at the appropriate points in the pipline. Note this is
/// called recursively in a tight loop during the process of capturing
Expand All @@ -559,7 +559,7 @@ module Destructure =
| tpv when isEmptyKeepTrying tpv ->
match tryObjectStructureDestructuring request with
| tpv when isEmptyKeepTrying tpv ->
match scalarStringCatchAllDestr request with
match scalarOriginCatchAllDestr request with
| tpv when isEmptyKeepTrying tpv -> TemplatePropertyValue.Empty
| tpv -> tpv
| tpv -> tpv
Expand Down