public ITraitResolution Resolve(ProjectionType projectionType, Type underlyingType) { if (projectionType == null) throw Error.ArgumentNull("projectionType"); if (underlyingType == null) throw Error.ArgumentNull("underlyingType"); var resolution = new StandardTraitResolution(projectionType, underlyingType); var assembly = underlyingType.Assembly; AddIncludedSpecs(resolution); AddDetectedSpecs(resolution, GetSharedSpecName (underlyingType), assembly); AddDetectedSpecs(resolution, GetPerTypeSpecName(underlyingType), assembly); return resolution; }
private static void AddDetectedSpec(StandardTraitResolution resolution, string name, Assembly assembly) { var type = assembly.GetType(name); if (type == null || !type.IsSubclassOf(typeof(TraitSpec))) return; var spec = TraitSpec.CreateInstance(type); if (spec == null) return; resolution.Add(spec); }
private void AddIncludedSpecs(StandardTraitResolution resolution) { var specs = this.specs; if (specs != null) foreach (var spec in specs) resolution.Add(spec); }
private void AddDetectedSpecs(StandardTraitResolution resolution, string name, Assembly containingAssembly) { var visitedContainingAssembly = false; var assemblies = this.assemblies; if (assemblies != null) { foreach (var assembly in assemblies) { if (assembly == containingAssembly) visitedContainingAssembly = true; AddDetectedSpec(resolution, name, assembly); } } if (!visitedContainingAssembly) AddDetectedSpec(resolution, name, containingAssembly); }