@ -34,19 +34,19 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
& & ! typeof ( IJsonLoadableState ) . IsAssignableFrom ( property . PropertyType )
& & ! typeof ( IJsonLoadableState ) . IsAssignableFrom ( property . PropertyType )
)
)
{
{
Logger . Trace ( "Skipping {Property} - read-only" , property . Name ) ;
Logger . Conditional Trace( "Skipping {Property} - read-only" , property . Name ) ;
return true ;
return true ;
}
}
// Check not JsonIgnore
// Check not JsonIgnore
if ( property . GetCustomAttributes ( typeof ( JsonIgnoreAttribute ) , true ) . Length > 0 )
if ( property . GetCustomAttributes ( typeof ( JsonIgnoreAttribute ) , true ) . Length > 0 )
{
{
Logger . Trace ( "Skipping {Property} - has [JsonIgnore]" , property . Name ) ;
Logger . Conditional Trace( "Skipping {Property} - has [JsonIgnore]" , property . Name ) ;
return true ;
return true ;
}
}
// Check not excluded type
// Check not excluded type
if ( SerializerIgnoredTypes . Contains ( property . PropertyType ) )
if ( SerializerIgnoredTypes . Contains ( property . PropertyType ) )
{
{
Logger . Trace (
Logger . Conditional Trace(
"Skipping {Property} - serializer ignored type {Type}" ,
"Skipping {Property} - serializer ignored type {Type}" ,
property . Name ,
property . Name ,
property . PropertyType
property . PropertyType
@ -56,7 +56,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
// Check not ignored name
// Check not ignored name
if ( SerializerIgnoredNames . Contains ( property . Name , StringComparer . Ordinal ) )
if ( SerializerIgnoredNames . Contains ( property . Name , StringComparer . Ordinal ) )
{
{
Logger . Trace ( "Skipping {Property} - serializer ignored name" , property . Name ) ;
Logger . Conditional Trace( "Skipping {Property} - serializer ignored name" , property . Name ) ;
return true ;
return true ;
}
}
@ -71,7 +71,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
// Has JsonIncludeAttribute
// Has JsonIncludeAttribute
if ( property . GetCustomAttributes ( typeof ( JsonIncludeAttribute ) , true ) . Length > 0 )
if ( property . GetCustomAttributes ( typeof ( JsonIncludeAttribute ) , true ) . Length > 0 )
{
{
Logger . Trace ( "Including {Property} - has [JsonInclude]" , property . Name ) ;
Logger . Conditional Trace( "Including {Property} - has [JsonInclude]" , property . Name ) ;
return true ;
return true ;
}
}
@ -94,7 +94,11 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
{
{
// Get all of our properties using reflection
// Get all of our properties using reflection
var properties = GetType ( ) . GetProperties ( ) ;
var properties = GetType ( ) . GetProperties ( ) ;
Logger . Trace ( "Serializing {Type} with {Count} properties" , GetType ( ) , properties . Length ) ;
Logger . ConditionalTrace (
"Serializing {Type} with {Count} properties" ,
GetType ( ) ,
properties . Length
) ;
foreach ( var property in properties )
foreach ( var property in properties )
{
{
@ -108,7 +112,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
is JsonPropertyNameAttribute jsonPropertyName
is JsonPropertyNameAttribute jsonPropertyName
)
)
{
{
Logger . Trace (
Logger . Conditional Trace(
"Deserializing {Property} ({Type}) with JsonPropertyName {JsonPropertyName}" ,
"Deserializing {Property} ({Type}) with JsonPropertyName {JsonPropertyName}" ,
property . Name ,
property . Name ,
property . PropertyType ,
property . PropertyType ,
@ -120,7 +124,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
// Check if property is in the JSON object
// Check if property is in the JSON object
if ( ! state . TryGetPropertyValue ( name , out var value ) )
if ( ! state . TryGetPropertyValue ( name , out var value ) )
{
{
Logger . Trace ( "Skipping {Property} - not in JSON object" , property . Name ) ;
Logger . Conditional Trace( "Skipping {Property} - not in JSON object" , property . Name ) ;
continue ;
continue ;
}
}
@ -133,7 +137,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
// For types that also implement IJsonLoadableState, defer to their load implementation
// For types that also implement IJsonLoadableState, defer to their load implementation
if ( typeof ( IJsonLoadableState ) . IsAssignableFrom ( property . PropertyType ) )
if ( typeof ( IJsonLoadableState ) . IsAssignableFrom ( property . PropertyType ) )
{
{
Logger . Trace (
Logger . Conditional Trace(
"Loading {Property} ({Type}) with IJsonLoadableState" ,
"Loading {Property} ({Type}) with IJsonLoadableState" ,
property . Name ,
property . Name ,
property . PropertyType
property . PropertyType
@ -171,7 +175,11 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
}
}
else
else
{
{
Logger . Trace ( "Loading {Property} ({Type})" , property . Name , property . PropertyType ) ;
Logger . ConditionalTrace (
"Loading {Property} ({Type})" ,
property . Name ,
property . PropertyType
) ;
var propertyValue = value . Deserialize ( property . PropertyType , SerializerOptions ) ;
var propertyValue = value . Deserialize ( property . PropertyType , SerializerOptions ) ;
property . SetValue ( this , propertyValue ) ;
property . SetValue ( this , propertyValue ) ;
@ -195,7 +203,11 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
{
{
// Get all of our properties using reflection.
// Get all of our properties using reflection.
var properties = GetType ( ) . GetProperties ( ) ;
var properties = GetType ( ) . GetProperties ( ) ;
Logger . Trace ( "Serializing {Type} with {Count} properties" , GetType ( ) , properties . Length ) ;
Logger . ConditionalTrace (
"Serializing {Type} with {Count} properties" ,
GetType ( ) ,
properties . Length
) ;
// Create a JSON object to store the state.
// Create a JSON object to store the state.
var state = new JsonObject ( ) ;
var state = new JsonObject ( ) ;
@ -218,7 +230,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
is JsonPropertyNameAttribute jsonPropertyName
is JsonPropertyNameAttribute jsonPropertyName
)
)
{
{
Logger . Trace (
Logger . Conditional Trace(
"Serializing {Property} ({Type}) with JsonPropertyName {JsonPropertyName}" ,
"Serializing {Property} ({Type}) with JsonPropertyName {JsonPropertyName}" ,
property . Name ,
property . Name ,
property . PropertyType ,
property . PropertyType ,
@ -230,7 +242,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
// For types that also implement IJsonLoadableState, defer to their implementation.
// For types that also implement IJsonLoadableState, defer to their implementation.
if ( typeof ( IJsonLoadableState ) . IsAssignableFrom ( property . PropertyType ) )
if ( typeof ( IJsonLoadableState ) . IsAssignableFrom ( property . PropertyType ) )
{
{
Logger . Trace (
Logger . Conditional Trace(
"Serializing {Property} ({Type}) with IJsonLoadableState" ,
"Serializing {Property} ({Type}) with IJsonLoadableState" ,
property . Name ,
property . Name ,
property . PropertyType
property . PropertyType
@ -245,7 +257,7 @@ public abstract class LoadableViewModelBase : ViewModelBase, IJsonLoadableState
}
}
else
else
{
{
Logger . Trace (
Logger . Conditional Trace(
"Serializing {Property} ({Type})" ,
"Serializing {Property} ({Type})" ,
property . Name ,
property . Name ,
property . PropertyType
property . PropertyType