Пример #1
0
        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;
        }
Пример #2
0
        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);
        }
Пример #3
0
 private void AddIncludedSpecs(StandardTraitResolution resolution)
 {
     var specs = this.specs;
     if (specs != null)
         foreach (var spec in specs)
             resolution.Add(spec);
 }
Пример #4
0
        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);
        }