示例#1
0
 public static ICachedBlob <A> a <A>(
     ISerializedRW <A> rw, PathStr path, A defaultValue,
     ILog log = null, Log.Level onDeserializeFailureLogLevel = Log.Level.ERROR
     )
 {
     log = log ?? Log.d;
     return(new FileCachedBlob(path).bimap(BiMapper.a(
                                               (byte[] bytes) => {
         var deserializedOpt = rw.deserialize(bytes, 0);
         if (deserializedOpt.isNone)
         {
             if (log.willLog(onDeserializeFailureLogLevel))
             {
                 log.log(
                     onDeserializeFailureLogLevel,
                     $"Can't deserialize {path}, deleting and returning default value."
                     );
             }
             clear(path).getOrLog($"Couldn't clear file: '{path}'", log: log);
             return defaultValue;
         }
         return deserializedOpt.__unsafeGetValue.value;
     },
                                               a => rw.serialize(a).toArray()
                                               )));
 }
示例#2
0
文件: exts.cs 项目: Marwan0/tlplib
 public static PrefVal <B> bimap <A, B>(
     this PrefVal <A> val, BiMapper <A, B> bimap
     ) => new PrefValMapper <A, B>(val, bimap);
示例#3
0
文件: mapper.cs 项目: ArnasJ/tlplib
 public PrefValMapper(PrefVal <A> backing, BiMapper <A, B> bimap)
 {
     this.backing = backing;
     this.bimap   = bimap;
 }
示例#4
0
 public static ICache <B> bimap <A, B>(this ICache <A> cache, BiMapper <A, B> bimap) =>
 new ICacheMapper <A, B>(cache, bimap);
示例#5
0
 public ICacheMapper(ICache <A> backing, BiMapper <A, B> bimap)
 {
     this.backing = backing;
     this.bimap   = bimap;
 }
示例#6
0
 public static ICachedBlob <string> toStringBlob(
     this ICachedBlob <byte[]> blob, Encoding encoding = null
     ) => blob.bimap(BiMapper.byteArrString(encoding));
示例#7
0
 public static ICachedBlob <B> bimap <A, B>(
     this ICachedBlob <A> blob, BiMapper <A, B> bimap
     ) => new ICachedBlobMapper <A, B>(blob, bimap);
示例#8
0
 public ICachedBlobTestBiMap()
 {
     blob       = new ICachedBlobTestImpl <int>();
     mappedBlob = blob.bimap(BiMapper.a <int, string>(i => i.ToString(), int.Parse));
 }