You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConvertTo-Expression Make the potential loss of type fidelity clearer in the read-me #73
It is implied by your Get-UICulture example, for instance, but I suggest pointing out the constraints on type fidelity explicitly (which types can actually be fully round-tripped).
A PSLeafNode terminates a PSNode branch and doesn't have any child nodes attached.
A value contained by a PSLeafNode is [Value], [String] or a [ScriptBlock] and is not
enumerable and doesn't contain any object properties (except for the three mentioned types).
The code piece that defines the PSNode fidelity is:
the (embedded) object expression is able to round trip.
An object is able to roundtrip if the resulted expression of the object itself or one of
its properties (prefixed with the type initializer) can be used to rebuild the object.
The advantage of the default fidelity is that the resulted expression round trips (aka the
object might be rebuild from the expression), the disadvantage is that information hold by
less significant properties is lost (as e.g. timezone information in a DateTime] object).
The advantage of the high fidelity switch is that all the information of the underlying
properties is shown, yet any constrained or full object type will likely fail to rebuild
due to constructor limitations such as readonly property.
The static [PSSerialize]::RoundTripProperty dictionary defines the round trip property.
Unless the -HighFidelity switch is set, the serialization will stop (even if it concerns a PSCollectionNode)
when the specific property type is reached.
An empty string will return the string representation of the object: "<Object>"
Any other string will return the string representation of the object property: "$(<Object>.<Property>)"
A ScriptBlock will be invoked and the result will be used for the object value
(The scope for this fidelity feature is basically only for constrained language mode)
changed the title [-]Make the potential loss of type fidelity clearer in the read-me[/-][+]`ConvertTo-Expression` Make the potential loss of type fidelity clearer in the read-me[/+]on Apr 15, 2024
Activity
iRon7 commentedon Apr 11, 2024
The object parser's fidelity is defined by:
[PSLeafNode]A PSLeafNode terminates a PSNode branch and doesn't have any child nodes attached.
A value contained by a PSLeafNode is
[Value],[String]or a [ScriptBlock]and is notenumerable and doesn't contain any object properties (except for the three mentioned types).
The code piece that defines the
PSNodefidelity is:The
ConvertTo-Expressioncmdlet's fidelity is further limited to:-HighFidelityIf the
-HighFidelityswitch is supplied, all nested object properties will be serialized.By default the fidelity of an object expression will end if:
An object is able to roundtrip if the resulted expression of the object itself or one of
its properties (prefixed with the type initializer) can be used to rebuild the object.
The advantage of the default fidelity is that the resulted expression round trips (aka the
object might be rebuild from the expression), the disadvantage is that information hold by
less significant properties is lost (as e.g. timezone information in a
DateTime]object).The advantage of the high fidelity switch is that all the information of the underlying
properties is shown, yet any constrained or full object type will likely fail to rebuild
due to constructor limitations such as readonly property.
The static
[PSSerialize]::RoundTripPropertydictionary defines the round trip property.Unless the
-HighFidelityswitch is set, the serialization will stop (even if it concerns aPSCollectionNode)when the specific property type is reached.
"<Object>""$(<Object>.<Property>)"(The scope for this fidelity feature is basically only for constrained language mode)
[-]Make the potential loss of type fidelity clearer in the read-me[/-][+]`ConvertTo-Expression` Make the potential loss of type fidelity clearer in the read-me[/+]