public ProcessingContext(ObjectCache cache, CompositionContainer container, IEnumerable<IAssetFilter> filters, IAssemblyLoader assemblyLoader, XElement element, HashSet<Asset> references, int phase, IAssetExplorer assetExplorer) { this._filters = filters.ToArray(); this.Element = element; this._references = references; AssetExplorer = assetExplorer; Container = container; this.Phase = phase; this.Cache = cache; this.AssemblyLoader = assemblyLoader; }
private static void Discover(IAssetExplorer assetExplorer, Asset asset, List<Asset> ret, IFilterContext filter) { if (filter != null && filter.IsFiltered(asset)) return; ret.Add(asset); IEnumerable<Asset> childAssets = assetExplorer.GetChildren(asset); foreach (Asset childAsset in childAssets) Discover(assetExplorer, childAsset, ret, filter); }
protected virtual void BuildHierarchy(XElement parentNode, LinkedListNode<Asset> hierarchy, HashSet<Asset> references, HashSet<Asset> emittedAssets, int phase, IAssetExplorer assetExplorer) { if (hierarchy == null) return; IAssemblyLoader assemblyLoader = new ReflectionOnlyAssemblyLoader(this._cache, this._assemblyPaths.Select(Path.GetDirectoryName)); Asset asset = hierarchy.Value; IProcessingContext pctx = new ProcessingContext(this._cache, this._container, this._filters, assemblyLoader, parentNode, references, phase, assetExplorer); XElement newElement; // add asset to list of generated assets emittedAssets.Add(asset); // dispatch depending on type switch (asset.Type) { case AssetType.Namespace: newElement = parentNode.XPathSelectElement(string.Format("namespace[@assetId = '{0}']", asset)); if (newElement == null) newElement = this.GenerateNamespaceElement(pctx, asset); break; case AssetType.Type: newElement = parentNode.XPathSelectElement(string.Format("*[@assetId = '{0}']", asset)); if (newElement == null) newElement = this.GenerateTypeElement(pctx, asset); break; case AssetType.Method: newElement = parentNode.XPathSelectElement(string.Format("*[@assetId = '{0}']", asset)); if (newElement == null) newElement = this.GenerateMethodElement(pctx, asset); break; case AssetType.Field: newElement = parentNode.XPathSelectElement(string.Format("field[@assetId = '{0}']", asset)); if (newElement == null) newElement = this.GenerateFieldElement(pctx, asset); break; case AssetType.Event: newElement = parentNode.XPathSelectElement(string.Format("event[@assetId = '{0}']", asset)); if (newElement == null) newElement = this.GenerateEventElement(pctx, asset); break; case AssetType.Property: newElement = parentNode.XPathSelectElement(string.Format("property[@assetId = '{0}']", asset)); if (newElement == null) newElement = this.GeneratePropertyElement(pctx, asset); break; case AssetType.Assembly: newElement = parentNode.XPathSelectElement(string.Format("assembly[@assetId = '{0}']", asset)); if (newElement == null) newElement = this.GenerateAssemblyElement(pctx, asset); break; default: throw new ArgumentOutOfRangeException(); } this.BuildHierarchy(newElement, hierarchy.Next, references, emittedAssets, phase, assetExplorer); }
protected virtual List<Asset> DiscoverAssets(Asset assemblyAsset, IAssetExplorer assetExplorer, IFilterContext filterContext) { List<Asset> assets = new List<Asset>(); using (TraceSources.GeneratorSource.TraceActivity("Discovering assets")) { if (TraceSources.GeneratorSource.Switch.ShouldTrace(TraceEventType.Verbose)) { foreach (Asset asset in assetExplorer.Discover(assemblyAsset, filterContext)) { TraceSources.GeneratorSource.TraceVerbose(asset.Id); assets.Add(asset); } } else assets.AddRange(assetExplorer.Discover(assemblyAsset, filterContext)); } // remove all namespaces, they will be added through the HierarchyBuilder anyway so this is an easy way to prevent empty namespaces assets.RemoveAll(a => a.Type == AssetType.Namespace); return assets; }