/// <summary> /// 安全地读入数组字段 /// </summary> /// <param name="bsonReader">Bson读取器</param> /// <param name="expected">字段名</param> /// <param name="read">字段名缓存</param> /// <param name="parser">数组元素读取器</param> /// <returns>读取结果</returns> public static List <T> ReadArray <T>(this IBsonReader bsonReader, string expected, ref string read, Func <IBsonReader, T> parser) { if (!ReadPrep(bsonReader, expected, ref read)) { return(null); } var lst = new List <T>(); bsonReader.ReadStartArray(); while (!bsonReader.IsEndOfArray()) { lst.Add(parser(bsonReader)); } bsonReader.ReadEndArray(); return(lst); }