public CatalogCache(Type stubType, ICachedComposablePartCatalogSite cachedCatalogSite)
            {
                Assumes.NotNull(stubType);

                cachedCatalogSite       = cachedCatalogSite ?? new EmptyCachedComposablePartCatalogSite();
                this._stubType          = stubType;
                this._cachedCatalogSite = cachedCatalogSite;

                // Get catalog index
                MethodInfo getIndexMethod = ComposablePartCatalogAssemblyCacheReader.GetCacheTypeMethod(this._stubType, CacheStructureConstants.CachingStubGetCatalogIndexMethodName, BindingFlags.Public | BindingFlags.Static);
                Func <IDictionary <string, IEnumerable <IntPtr> > > getIndex = (Func <IDictionary <string, IEnumerable <IntPtr> > >)Delegate.CreateDelegate(typeof(Func <IDictionary <string, IEnumerable <IntPtr> > >), getIndexMethod);

                this._catalogIndex = getIndex.Invoke();

                // Get part factory
                MethodInfo getPartFactoryMethod = ComposablePartCatalogAssemblyCacheReader.GetCacheTypeMethod(this._stubType, CacheStructureConstants.CachingStubGetPartFactoryMethodName, BindingFlags.Static | BindingFlags.Public);

                this._getPartFactory = (Func <IntPtr, ComposablePartDefinition>)Delegate.CreateDelegate(typeof(Func <IntPtr, ComposablePartDefinition>), getPartFactoryMethod);

                // get fields
                FieldInfo importDefinitionFactoryField = ComposablePartCatalogAssemblyCacheReader.GetCacheTypeField(this._stubType, CacheStructureConstants.CachingStubImportDefinitionFactoryFieldName, BindingFlags.Public | BindingFlags.Static);
                FieldInfo exportDefinitionFactoryField = ComposablePartCatalogAssemblyCacheReader.GetCacheTypeField(this._stubType, CacheStructureConstants.CachingStubExportDefinitionFactoryFieldName, BindingFlags.Public | BindingFlags.Static);
                FieldInfo partDefinitionFactoryField   = ComposablePartCatalogAssemblyCacheReader.GetCacheTypeField(this._stubType, CacheStructureConstants.CachingStubPartDefinitionFactoryFieldName, BindingFlags.Public | BindingFlags.Static);

                // initialize the cache fields with the factory methods
                importDefinitionFactoryField.SetValue(null, new Func <ComposablePartDefinition, IDictionary <string, object>, ImportDefinition>(this._cachedCatalogSite.CreateImportDefinitionFromCache));
                exportDefinitionFactoryField.SetValue(null, new Func <ComposablePartDefinition, IDictionary <string, object>, ExportDefinition>(this._cachedCatalogSite.CreateExportDefinitionFromCache));
                partDefinitionFactoryField.SetValue(null, new Func <IDictionary <string, object>, Func <ComposablePartDefinition, IEnumerable <ImportDefinition> >, Func <ComposablePartDefinition, IEnumerable <ExportDefinition> >, ComposablePartDefinition>(this.InternalCreatePartDefinitionFromCache));
            }
        public static ICachedComposablePartCatalog ReadCatalogFromCache(AssemblyName assemblyName)
        {
            Requires.NotNull(assemblyName, "assemblyName");

            Assembly assembly = Assembly.Load(assemblyName);

            using (ComposablePartCatalogAssemblyCacheReader reader = new ComposablePartCatalogAssemblyCacheReader(assembly))
            {
                return (ICachedComposablePartCatalog)reader.ReadRootCatalog();
            }
        }
        protected override ComposablePartCatalogCache ReadCacheCore(object cacheToken)
        {
            string rootStubSuffix = cacheToken as string;

            if (rootStubSuffix == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Strings.InvalidCacheToken, cacheToken), "cacheToken");
            }

            Type stubType = ComposablePartCatalogAssemblyCacheReader.GetCacheType(this._cacheAssembly, string.Format(CultureInfo.InvariantCulture, "{0}{1}", CacheStructureConstants.CachingStubTypeNamePrefix, rootStubSuffix));

            return(new ComposablePartCatalogAssemblyCache(stubType, this));
        }
        public ComposablePartCatalogAssemblyCacheReader(Assembly cacheAssembly)
        {
            Requires.NotNull(cacheAssembly, "cacheAssembly");
            this._cacheAssembly = cacheAssembly;

            // read the entry point
            Type       entryPointType    = ComposablePartCatalogAssemblyCacheReader.GetCacheType(this._cacheAssembly, CacheStructureConstants.EntryPointTypeName);
            MethodInfo getRootStubMethod = ComposablePartCatalogAssemblyCacheReader.GetCacheTypeMethod(entryPointType, CacheStructureConstants.EntryPointGetRootStubMethodName, BindingFlags.Static | BindingFlags.Public);

            Func <string> getRootStub = (Func <string>)Delegate.CreateDelegate(typeof(Func <string>), getRootStubMethod);

            this._rootStubSuffix = getRootStub.Invoke();
        }
        public ComposablePartCatalogAssemblyCache(Type stubType, ComposablePartCatalogCacheReader reader)
        {
            Assumes.NotNull(stubType);
            Assumes.NotNull(reader);

            this._stubType = stubType;
            this._reader   = reader;

            // Get catalog metadata
            MethodInfo getCatalogMetadataMethod = ComposablePartCatalogAssemblyCacheReader.GetCacheTypeMethod(this._stubType, CacheStructureConstants.CachingStubGetCatalogMetadata, BindingFlags.Public | BindingFlags.Static);
            Func <IDictionary <string, object> > getCatalogMetadata = (Func <IDictionary <string, object> >)Delegate.CreateDelegate(typeof(Func <IDictionary <string, object> >), getCatalogMetadataMethod);

            this._metadata = getCatalogMetadata.Invoke();
        }