@@ -61,20 +61,22 @@ public PropertyCSScriptSerializer(IReadOnlyDictionary<string, Func<T, object>> p
6161 {
6262 }
6363
64+ // To not serialize properties give default that's always equal to the property value
6465 public PropertyCSScriptSerializer ( IReadOnlyDictionary < string , Func < T , object > > propertyValueGetters ,
6566 IReadOnlyCollection < Func < T , object > > constructorParameterGetters ,
6667 IReadOnlyDictionary < string , Func < T , object > > propertyDefaultGetters )
6768 : this ( constructorParameterGetters )
6869 {
69- var properties = typeof ( T ) . GetTypeInfo ( )
70- . GetProperties ( BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic )
71- . ToDictionary ( p => p . Name ) ;
72- _propertyData = propertyValueGetters . Select (
73- p => new PropertyData (
74- p . Key ,
75- properties [ p . Key ] . PropertyType ,
76- p . Value ,
77- propertyDefaultGetters . GetValueOrDefault ( p . Key , o => GetDefault ( properties [ p . Key ] . PropertyType ) ) ) )
70+ var referencedProperties = typeof ( T ) . GetTypeInfo ( )
71+ . GetProperties ( BindingFlags . Instance | BindingFlags . Public )
72+ . Where ( p => propertyValueGetters . ContainsKey ( p . Name ) ) ;
73+ _propertyData = typeof ( T ) . GetRuntimeProperties ( ) . Where ( IsCandidateProperty )
74+ . Concat ( referencedProperties ) . Distinct ( ) . Select (
75+ p => new PropertyData (
76+ p . Name ,
77+ p . PropertyType ,
78+ propertyValueGetters . GetValueOrDefault ( p . Name , CreatePropertyInitializer ( p ) ) ,
79+ propertyDefaultGetters . GetValueOrDefault ( p . Name , o => GetDefault ( p . PropertyType ) ) ) )
7880 . ToArray ( ) ;
7981 }
8082
0 commit comments