-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
namespace Loader; | ||
|
||
public abstract class EntryPointAttributeBase : Attribute | ||
public enum ModulePriority | ||
{ | ||
internal abstract IPlugin CreateInstance(); | ||
Library, | ||
Front, | ||
High, | ||
Normal | ||
} | ||
|
||
public abstract class ModuleEntryPointAttributeBase | ||
: Attribute, | ||
IComparer<ModuleEntryPointAttributeBase> | ||
{ | ||
internal abstract IModule CreateInstance(); | ||
internal ModulePriority Priority { get; set; } | ||
|
||
//for sort | ||
public int Compare(ModuleEntryPointAttributeBase? x, ModuleEntryPointAttributeBase? y) | ||
{ | ||
if (ReferenceEquals(x, y)) | ||
return 0; | ||
if (ReferenceEquals(null, y)) | ||
return 1; | ||
if (ReferenceEquals(null, x)) | ||
return -1; | ||
return x.Priority.CompareTo(y.Priority); | ||
} | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] | ||
public sealed class EntryPointAttribute<T> : EntryPointAttributeBase | ||
where T : IPlugin, new() | ||
public sealed class ModuleEntryPointAttribute<T> : ModuleEntryPointAttributeBase | ||
where T : IModule, new() | ||
{ | ||
internal override IPlugin CreateInstance() => new T(); | ||
public ModuleEntryPointAttribute(ModulePriority priority = ModulePriority.Normal) | ||
{ | ||
Priority = priority; | ||
} | ||
|
||
internal override IModule CreateInstance() => new T(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
namespace Loader; | ||
|
||
public interface IPlugin : IDisposable | ||
public interface IModule : IDisposable | ||
{ | ||
string Name { get; } | ||
void Initialize(); | ||
void Unload(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters