@@ -19,22 +19,58 @@ public static ViewModels.Device MapFromProtobuffer(CanOpenDevice source)
1919 . ForMember ( dest => dest . CreatedBy , opt => opt . MapFrom ( src => src . CreatedBy ) )
2020 . ForMember ( dest => dest . ModificationTime , opt => opt . MapFrom ( src => src . ModificationTime ) )
2121 . ForMember ( dest => dest . ModifiedBy , opt => opt . MapFrom ( src => src . ModifiedBy ) ) ;
22+ cfg . CreateMap < Google . Protobuf . Collections . MapField < string , OdObject > , ViewModels . ObjectDictionary > ( ) . ConvertUsing < ODConverter > ( ) ;
2223 cfg . CreateMap < CanOpenDevice , ViewModels . Device > ( )
2324 . ForMember ( dest => dest . FileInfo , opt => opt . MapFrom ( src => src . FileInfo ) )
2425 . ForMember ( dest => dest . DeviceInfo , opt => opt . MapFrom ( src => src . DeviceInfo ) )
2526 . ForMember ( dest => dest . DeviceCommissioning , opt => opt . MapFrom ( src => src . DeviceCommissioning ) )
26- . ForPath ( dest => dest . Objects . Data , opt => opt . MapFrom ( src => src . Objects ) ) ;
27-
27+ . ForMember ( dest => dest . Objects , opt => opt . MapFrom ( src => src . Objects ) ) ;
2828 cfg . CreateMap < CanOpen_DeviceInfo , ViewModels . DeviceInfo > ( ) ;
2929 cfg . CreateMap < CanOpen_DeviceCommissioning , ViewModels . DeviceCommissioning > ( ) ;
30- cfg . CreateMap < OdObject , ViewModels . OdObject > ( ) ;
31-
3230 } ) ;
3331 config . AssertConfigurationIsValid ( ) ;
3432 var mapper = config . CreateMapper ( ) ;
3533 var result = mapper . Map < ViewModels . Device > ( source ) ;
3634 return result ;
3735 }
36+ public class ODConverter : ITypeConverter < Google . Protobuf . Collections . MapField < string , OdObject > , ViewModels . ObjectDictionary > ,
37+ ITypeConverter < ViewModels . ObjectDictionary , Google . Protobuf . Collections . MapField < string , OdObject > >
38+ {
39+ public ViewModels . ObjectDictionary Convert ( Google . Protobuf . Collections . MapField < string , OdObject > source , ViewModels . ObjectDictionary destination , ResolutionContext context )
40+ {
41+ var config = new MapperConfiguration ( cfg =>
42+ {
43+ cfg . CreateMap < OdObject , ViewModels . OdObject > ( ) ;
44+ cfg . CreateMap < OdSubObject , ViewModels . OdSubObject > ( ) ;
45+ } ) ;
46+ config . AssertConfigurationIsValid ( ) ;
47+ var mapper = config . CreateMapper ( ) ;
48+
49+ destination = [ ] ;
50+ foreach ( var item in source )
51+ {
52+ destination . Add ( item . Key , mapper . Map < ViewModels . OdObject > ( item . Value ) ) ;
53+ }
54+ return destination ;
55+ }
56+ public Google . Protobuf . Collections . MapField < string , OdObject > Convert ( ViewModels . ObjectDictionary source , Google . Protobuf . Collections . MapField < string , OdObject > destination , ResolutionContext context )
57+ {
58+ var config = new MapperConfiguration ( cfg =>
59+ {
60+ cfg . CreateMap < ViewModels . OdObject , OdObject > ( ) ;
61+ cfg . CreateMap < ViewModels . OdSubObject , OdSubObject > ( ) ;
62+ } ) ;
63+ config . AssertConfigurationIsValid ( ) ;
64+ var mapper = config . CreateMapper ( ) ;
65+
66+ destination = [ ] ;
67+ foreach ( var item in source )
68+ {
69+ destination . Add ( item . Key , mapper . Map < OdObject > ( item . Value ) ) ;
70+ }
71+ return destination ;
72+ }
73+ }
3874
3975 public static CanOpenDevice MapToProtobuffer ( ViewModels . Device source )
4076 {
0 commit comments