Ejemplo n.º 1
0
    public PluginInfo(Type type, PluginSetConstructionInfo constructionInfo, IPluginInfoProvider pluginInfoProvider)
    {
        if (type.IsAbstract)
        {
            throw Errors.PluginIsAbstract(type);
        }
        if (type.IsNotPublic)
        {
            throw Errors.PluginIsNonPublic(type);
        }

        Type      = type;
        Ancestors = ImmutableArray.Create(
            type.GetAllBaseTypes().Select(t => (TypeRef)t).ToArray());
        Interfaces = ImmutableArray.Create(
            type.GetInterfaces().Select(t => (TypeRef)t).ToArray());
        CastableTo = ImmutableHashSet.Create(
            Ancestors.AddRange(Interfaces).Add(type).ToArray());
        Capabilities = pluginInfoProvider.GetCapabilities(type);
        Dependencies = pluginInfoProvider.GetDependencies(type);
        var allAssemblyRefs = constructionInfo.AllAssemblyRefs[type.Assembly];

        AllDependencies = constructionInfo.Plugins
                          .Where(p => p != type && (
                                     allAssemblyRefs.Contains(p.Assembly) ||
                                     CastableTo.Contains(p)))
                          .Select(t => (TypeRef)t)
                          .Concat(Dependencies)
                          .ToImmutableHashSet();
    }
Ejemplo n.º 2
0
        public PluginInfo(Type type, PluginSetConstructionInfo constructionInfo)
        {
            Type      = type;
            Ancestors = ImmutableArray.Create(
                type.GetAllBaseTypes().Select(t => (TypeRef)t).ToArray());
            Interfaces = ImmutableArray.Create(
                type.GetInterfaces().Select(t => (TypeRef)t).ToArray());
            CastableTo = ImmutableHashSet.Create(
                Ancestors.AddRange(Interfaces).Add(type).ToArray());
            Capabilities = ImmutableDictionary <string, object> .Empty;
            Dependencies = ImmutableHashSet <TypeRef> .Empty;

            object?tmpPlugin = null;

            try {
                tmpPlugin = constructionInfo.PluginFactory.Create(type);
            }
            catch (Exception) {
                // There might be plugins we can't construct -- mainly,
                // b/c their constructors aren't written properly to support
                // temporary plugin factory.
                // All we can do here is to ignore this exception & assume
                // these plugins can't provide capabilities and dependencies.
            }

            if (tmpPlugin is IHasCapabilities hc)
            {
                Capabilities = hc.Capabilities;
            }
            if (tmpPlugin is IHasDependencies hd)
            {
                Dependencies = hd.Dependencies.Select(t => (TypeRef)t).ToImmutableHashSet();
            }

            var allAssemblyRefs = constructionInfo.AllAssemblyRefs[type.Assembly];

            AllDependencies = constructionInfo.Plugins
                              .Where(p => p != type && (
                                         allAssemblyRefs.Contains(p.Assembly) ||
                                         CastableTo.Contains(p)))
                              .Select(t => (TypeRef)t)
                              .Concat(Dependencies)
                              .ToImmutableHashSet();
        }