Esempio n. 1
0
        internal void StoreItem(int index, T value)
        {
            FileStats.AddWrite();
            string path = prefix + index.ToString(CultureInfo.InvariantCulture) + ".bin";

            if (object.ReferenceEquals(value, null) || value.Equals(default(T)))
            {
                File.Delete(path);
            }
            else
            {
                IFormatter formatter = new BinaryFormatter();
                using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    formatter.Serialize(stream, value);
                }
            }
        }
Esempio n. 2
0
 public T this[int index]
 {
     get
     {
         FileStats.AddRead();
         string path = prefix + index.ToString(CultureInfo.InvariantCulture) + ".bin";
         if (!File.Exists(path))
         {
             return(default(T));
         }
         IFormatter formatter = new BinaryFormatter();
         using (var stream = new FileStream(prefix + index.ToString(CultureInfo.InvariantCulture) + ".bin", FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             return((T)formatter.Deserialize(stream));
         }
     }
     set { if (!containsFileArrays)
           {
               StoreItem(index, value);
           }
     }
 }