/// <summary> /// Initializes a new instance of the <see cref="BuildManagerTypeCache"/> class. /// </summary> /// <param name="buildManager">The build manager.</param> /// <param name="serializer">The serializer.</param> public BuildManagerTypeCache(IBuildManager buildManager, ITypeCacheSerializer serializer) { if (buildManager == null) throw new ArgumentNullException("buildManager"); if (serializer == null) throw new ArgumentNullException("serializer"); BuildManager = buildManager; Serializer = serializer; }
/// <summary> /// Initializes a new instance of the <see cref="BuildManagerTypeCache"/> class. /// </summary> /// <param name="buildManager">The build manager.</param> /// <param name="serializer">The serializer.</param> public BuildManagerTypeCache(IBuildManager buildManager, ITypeCacheSerializer serializer) { if (buildManager == null) { throw new ArgumentNullException("buildManager"); } if (serializer == null) { throw new ArgumentNullException("serializer"); } BuildManager = buildManager; Serializer = serializer; }
/// <summary> /// Saves the types to cache. /// </summary> /// <param name="buildManager">The build manager.</param> /// <param name="cacheName">Name of the cache.</param> /// <param name="matchingTypes">The matching types.</param> /// <param name="serializer">The serializer.</param> public static void SaveTypesToCache(IBuildManager buildManager, string cacheName, IEnumerable <Type> matchingTypes, ITypeCacheSerializer serializer) { try { using (var s = buildManager.CreateCachedFile(cacheName)) if (s != null) { using (var w = new StreamWriter(s)) serializer.SerializeTypes(matchingTypes, w); } } catch { } }
/// <summary> /// Reads the types from cache. /// </summary> /// <param name="buildManager">The build manager.</param> /// <param name="cacheName">Name of the cache.</param> /// <param name="predicate">The predicate.</param> /// <param name="serializer">The serializer.</param> /// <returns></returns> public static IEnumerable <Type> ReadTypesFromCache(IBuildManager buildManager, string cacheName, Predicate <Type> predicate, ITypeCacheSerializer serializer) { Func <Type, bool> func = type => (TypeIsPublicClass(type) && predicate(type)); try { using (var s = buildManager.ReadCachedFile(cacheName)) if (s != null) { using (var r = new StreamReader(s)) { var source = serializer.DeserializeTypes(r); if (source != null) { if (source.All(func)) { return(source); } } } } } catch { } return(null); }