コード例 #1
0
ファイル: TargetTypeDictionary.cs プロジェクト: zyj0021/SHFB
        /// <summary>
        /// Test serialization of the target dictionaries
        /// </summary>
        /// <param name="folder">The folder in which to place the serialized files</param>
        public void SerializeDictionary(string folder)
        {
            using (TargetTypeDictionary tempTD = new TargetTypeDictionary())
            {
                TargetDictionary targetDictionary;
                BinaryFormatter  bf = new BinaryFormatter();
                string           filename;

                foreach (var td in targetDictionaries.Reverse <KeyValuePair <ReferenceLinkType, TargetDictionary> >())
                {
                    filename = Path.Combine(folder, td.Value.DictionaryId);

                    // Fair warning, this is really slow for the main .NET Framework target dictionary hence the
                    // reason not to offer the option to serialize the InMemoryTargetDictionary to a persistent cache.
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                    {
                        bf.Serialize(fs, td.Value);
                    }

                    using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        targetDictionary = (TargetDictionary)bf.Deserialize(fs);
                    }

                    tempTD.Add(ReferenceLinkType.None, targetDictionary);
                }

                tempTD.DumpTargetDictionary(Path.Combine(folder, "SerializedIn.xml"));
            }
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="targets">The target dictionary used to resolve links</param>
 public LinkTextResolver(TargetTypeDictionary targets)
 {
     this.targets = targets;
 }