Beispiel #1
0
        /// <summary>
        ///   Loads the generated types from the given assembly into this <see cref = "ModuleScope" />'s cache.
        /// </summary>
        /// <param name = "assembly">The assembly to load types from. This assembly must have been saved via <see
        ///    cref = "SaveAssembly(bool)" /> or
        ///   <see cref = "SaveAssembly()" />, or it must have the <see cref = "CacheMappingsAttribute" /> manually applied.</param>
        /// <remarks>
        ///   This method can be used to load previously generated and persisted proxy types from disk into this scope's type cache, e.g. in order
        ///   to avoid the performance hit associated with proxy generation.
        /// </remarks>
        public void LoadAssemblyIntoCache(Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            var cacheMappings = (CacheMappingsAttribute[])assembly.GetCustomAttributes(
                typeof(CacheMappingsAttribute),
                false
                );

            if (cacheMappings.Length == 0)
            {
                var message = string.Format(
                    "The given assembly '{0}' does not contain any cache information for generated types.",
                    assembly.FullName
                    );
                throw new ArgumentException(message, nameof(assembly));
            }

            foreach (var mapping in cacheMappings[0].GetDeserializedMappings())
            {
                var loadedType = assembly.GetType(mapping.Value);

                if (loadedType != null)
                {
                    typeCache.AddOrUpdateWithoutTakingLock(mapping.Key, loadedType);
                }
            }
        }
Beispiel #2
0
 public void RegisterInCache(CacheKey key, Type type)
 {
     typeCache.AddOrUpdateWithoutTakingLock(key, type);
 }