public bool SetParameters(PluginDetail detail) { var plugin = GetPlugin(detail.Type); if (plugin == null) { return(false); } var properties = plugin.GetType().GetProperties() .Where(it => it.GetCustomAttribute <RequiredParameterAttribute>() != null) .ToDictionary(it => it.Name, it => it); foreach (var parameter in detail.RequiredParameters) { if (properties.TryGetValue(parameter.Name, out var property) && parameter.Value.GetType() == property.PropertyType) { PluginParameterProvider.Put(plugin.GetType(), parameter.Name, parameter.Value); property.SetValue(plugin, parameter.Value); } } return(true); }
public void ResetParameters(string pluginType) { var plugin = GetPlugin(pluginType); if (plugin == null || !PluginDetails.TryGetValue(pluginType, out var detail)) { return; } var requiredParameters = new List <PluginParameter>(); foreach (var property in plugin.GetType().GetProperties()) { var attribute = property.GetCustomAttribute <RequiredParameterAttribute>(); if (attribute == null) { continue; } property.SetValue(plugin, attribute.DefaultValue); PluginParameterProvider.Put(plugin.GetType(), attribute.Name, attribute.DefaultValue); requiredParameters.Add(new PluginParameter() { Name = attribute.Name, Alias = attribute.Alias, Type = attribute.Type, IsReadOnly = attribute.IsReadOnly, Value = attribute.DefaultValue, Comment = attribute.Comment, }); } detail.RequiredParameters = requiredParameters; }