Make it possible to read plugin information from csproj attributes

This commit is contained in:
js6pak committed 2021-04-13 23:13:52 +02:00
1 parent 283f59b51f
commit e1a6fdda98
6 files changed
+26 -8

No files matched your search

@@ -5,6 +5,11 @@ namespace Impostor.Api.Plugins
[AttributeUsage(AttributeTargets.Class)]
public class ImpostorPluginAttribute : Attribute
{
public ImpostorPluginAttribute(string id)
{
Id = id;
}
public ImpostorPluginAttribute(string id, string name, string author, string version)
{
Id = id;
@@ -15,10 +20,10 @@ namespace Impostor.Api.Plugins
public string Id { get; }
public string Name { get; }
public string? Name { get; }
public string Author { get; }
public string? Author { get; }
public string Version { get; }
public string? Version { get; }
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ using Impostor.Api.Plugins;
namespace Impostor.Plugins.Debugger
{
[ImpostorPlugin("gg.impostor.debugger", "Debugger", "Gerard", "1.0.0")]
[ImpostorPlugin("gg.impostor.debugger")]
public class DebugPlugin : PluginBase
{
}
@@ -3,6 +3,10 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Library</OutputType>
<Version>1.0.0</Version>
<AssemblyTitle>Debugger</AssemblyTitle>
<Authors>Gerard</Authors>
</PropertyGroup>
<ItemGroup>
@@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging;
namespace Impostor.Plugins.Example
{
[ImpostorPlugin("gg.impostor.example", "Example", "AeonLucid", "1.0.0")]
[ImpostorPlugin("gg.impostor.example")]
public class ExamplePlugin : PluginBase
{
private readonly ILogger<ExamplePlugin> _logger;
@@ -2,6 +2,10 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>1.0.0</Version>
<AssemblyTitle>Example</AssemblyTitle>
<Authors>AeonLucid</Authors>
</PropertyGroup>
<ItemGroup>
@@ -14,6 +14,11 @@ namespace Impostor.Server.Plugins
{
_attribute = pluginType.GetCustomAttribute<ImpostorPluginAttribute>()!;
var assembly = pluginType.Assembly;
Name = _attribute.Name ?? assembly.GetCustomAttribute<AssemblyTitleAttribute>()?.Title ?? assembly.GetName().Name!;
Author = _attribute.Author ?? assembly.GetCustomAttribute<AssemblyCompanyAttribute>()?.Company ?? string.Empty;
Version = _attribute.Version ?? assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? assembly.GetName().Version!.ToString();
Dependencies = pluginType.GetCustomAttributes<ImpostorDependencyAttribute>().Select(t => new DependencyInformation(t)).ToList();
Startup = startup;
PluginType = pluginType;
@@ -21,11 +26,11 @@ namespace Impostor.Server.Plugins
public string Id => _attribute.Id;
public string Name => _attribute.Name;
public string Name { get; }
public string Author => _attribute.Author;
public string Author { get; }
public string Version => _attribute.Version;
public string Version { get; }
public List<DependencyInformation> Dependencies { get; }