DarkRift.Server.PluginFactory.GetAllSubtypes C# (CSharp) Method

GetAllSubtypes() private method

Returns a list of plugins found that are subtypes of that given.
private GetAllSubtypes ( Type type ) : Type[]
type Type The type to filter by.
return Type[]
        internal Type[] GetAllSubtypes(Type type)
        {
            return types.Values
                .Where(t => t.IsSubclassOf(type))
                .ToArray();
        }

Usage Example

示例#1
0
        /// <summary>
        ///     Loads the plugins found by the plugin factory.
        /// </summary>
        /// <param name="settings">The settings to load plugins with.</param>
        internal void LoadPlugins(ServerSpawnData.PluginsSettings settings)
        {
            Type[] types = pluginFactory.GetAllSubtypes(typeof(Plugin));

            foreach (Type type in types)
            {
                var s = settings.Plugins.FirstOrDefault(p => p.Type == type.Name);

                PluginLoadData loadData = new PluginLoadData(
                    type.Name,
                    server,
                    s?.Settings ?? new NameValueCollection(),
                    logManager.GetLoggerFor(type.Name),
#if PRO
                    metricsManager.GetMetricsCollectorFor(type.Name),
#endif
                    dataManager.GetResourceDirectory(type.Name)
                    );

                if (s?.Load ?? settings.LoadByDefault)
                {
                    LoadPlugin(type.Name, type, loadData, null, true);
                }
            }
        }