Esempio n. 1
0
		public static List<Type> GetFilteredTypesFromAssemblies(string cacheName, Predicate<Type> predicate, IBuildManager buildManager)
		{
			TypeCacheSerializer serializer = new TypeCacheSerializer();
			List<Type> list = ReadTypesFromCache(cacheName, predicate, buildManager, serializer);
			if (list != null)
			{
				return list;
			}
			list = FilterTypesInAssemblies(buildManager, predicate).ToList();
            SaveTypesToCache(cacheName, list, buildManager, serializer);
			return list;
		}
Esempio n. 2
0
		internal static void SaveTypesToCache(string cacheName, IList<Type> matchingTypes, IBuildManager buildManager, TypeCacheSerializer serializer)
		{
			try
			{
				Stream stream = buildManager.CreateCachedFile(cacheName);
				if (stream != null)
				{
					using (StreamWriter streamWriter = new StreamWriter(stream))
					{
						serializer.SerializeTypes(matchingTypes, streamWriter);
					}
				}
			}
			catch
			{
			}
		}
Esempio n. 3
0
		internal static List<Type> ReadTypesFromCache(string cacheName, Predicate<Type> predicate, IBuildManager buildManager, TypeCacheSerializer serializer)
		{
			try
			{
				Stream stream = buildManager.ReadCachedFile(cacheName);
				if (stream != null)
				{
					using (StreamReader streamReader = new StreamReader(stream))
					{
						List<Type> list = serializer.DeserializeTypes(streamReader);
						if (list != null)
						{
							if (list.All((Type type) => TypeIsPublicClass(type) && predicate(type)))
							{
								return list;
							}
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}