public static T ReadBlock <T>(this FileStream fileStream, long position) where T : Block { T block = null; Block b = BlockCache.TryGetSunkBlock(position);// 如果已经从数据库读出来过,就不应再读了。 if (b != null) { block = b as T; if (block == null) { throw new Exception("Two types of Block exists in the same position!"); } } else { fileStream.Seek(position, SeekOrigin.Begin); object obj = Consts.formatter.Deserialize(fileStream); block = obj as T; block.ThisPos = position; BlockCache.AddSunkBlock(block); } return(block); }