3
3
4
4
using System ;
5
5
using System . Collections . Concurrent ;
6
+ using System . Collections . Generic ;
6
7
using System . IO ;
8
+ using System . Linq ;
7
9
using System . Reflection ;
8
- using System . Runtime . Serialization . Formatters . Binary ;
10
+ using System . Xml . Serialization ;
9
11
using Microsoft . Win32 ;
10
12
11
13
namespace Microsoft . ClearScript . Util
@@ -71,8 +73,8 @@ private static bool ReadAssemblyTable(string rootPath)
71
73
{
72
74
using ( var stream = new FileStream ( filePath , FileMode . Open , FileAccess . Read , FileShare . Read ) )
73
75
{
74
- var formatter = new BinaryFormatter ( ) ;
75
- table = ( ConcurrentDictionary < string , string > ) formatter . Deserialize ( stream ) ;
76
+ var serializer = new XmlSerializer ( typeof ( AssemblyTableData ) ) ;
77
+ table = ( ( AssemblyTableData ) serializer . Deserialize ( stream ) ) . CreateTable ( ) ;
76
78
}
77
79
}
78
80
} ) ;
@@ -120,8 +122,8 @@ private static bool WriteAssemblyTable(string rootPath)
120
122
var filePath = GetFilePath ( rootPath ) ;
121
123
using ( var stream = new FileStream ( filePath , FileMode . OpenOrCreate , FileAccess . Write , FileShare . None ) )
122
124
{
123
- var formatter = new BinaryFormatter ( ) ;
124
- formatter . Serialize ( stream , table ) ;
125
+ var serializer = new XmlSerializer ( typeof ( AssemblyTableData ) ) ;
126
+ serializer . Serialize ( stream , new AssemblyTableData ( table ) ) ;
125
127
}
126
128
} ) ;
127
129
}
@@ -131,7 +133,7 @@ private static string GetFilePath(string rootPath)
131
133
var dirPath = Path . Combine ( rootPath , GetRuntimeVersionDirectoryName ( ) ) ;
132
134
Directory . CreateDirectory ( dirPath ) ;
133
135
134
- return Path . Combine ( dirPath , "AssemblyTable.bin " ) ;
136
+ return Path . Combine ( dirPath , "AssemblyTable.xml " ) ;
135
137
}
136
138
137
139
private static string GetRuntimeVersionDirectoryName ( )
@@ -142,4 +144,43 @@ private static string GetRuntimeVersionDirectoryName()
142
144
143
145
#endregion
144
146
}
147
+
148
+ /// <exclude/>
149
+ [ XmlRoot ( "AssemblyTable" ) ]
150
+ public sealed class AssemblyTableData
151
+ {
152
+ /// <exclude/>
153
+ [ XmlArray ] public List < Entry > Entries ;
154
+
155
+ /// <exclude/>
156
+ public AssemblyTableData ( )
157
+ {
158
+ }
159
+
160
+ /// <exclude/>
161
+ public AssemblyTableData ( ConcurrentDictionary < string , string > table )
162
+ {
163
+ Entries = table . Select ( pair => new Entry { Name = pair . Key , FullName = pair . Value } ) . ToList ( ) ;
164
+ }
165
+
166
+ /// <exclude/>
167
+ public ConcurrentDictionary < string , string > CreateTable ( )
168
+ {
169
+ return ( Entries is null ) ? null : new ConcurrentDictionary < string , string > ( Entries . Select ( entry => new KeyValuePair < string , string > ( entry . Name , entry . FullName ) ) ) ;
170
+ }
171
+
172
+ #region Nested type: Entry
173
+
174
+ /// <exclude/>
175
+ public sealed class Entry
176
+ {
177
+ /// <exclude/>
178
+ [ XmlAttribute ] public string Name { get ; set ; }
179
+
180
+ /// <exclude/>
181
+ [ XmlAttribute ] public string FullName { get ; set ; }
182
+ }
183
+
184
+ #endregion
185
+ }
145
186
}
0 commit comments