Skip to content

Commit adabb19

Browse files
committed
Updated to use Weikio.TypeGenerators
1 parent 2332577 commit adabb19

14 files changed

Lines changed: 108 additions & 502 deletions

File tree

src/Weikio.PluginFramework.Abstractions/PluginNameOptions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ public class PluginNameOptions
4343
{
4444
var versionInfo = FileVersionInfo.GetVersionInfo(assemblyLocation);
4545

46-
version = Version.Parse(versionInfo.FileVersion);
46+
if (string.IsNullOrWhiteSpace(versionInfo.FileVersion))
47+
{
48+
version = new Version(1, 0, 0, 0);
49+
}
50+
else if (string.Equals(versionInfo.FileVersion, "0.0.0.0"))
51+
{
52+
version = new Version(1, 0, 0, 0);
53+
}
54+
else
55+
{
56+
version = Version.Parse(versionInfo.FileVersion);
57+
}
4758
}
4859
else
4960
{

src/Weikio.PluginFramework.Catalogs.Roslyn/RegularInitializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Reflection;
44
using System.Text;
55
using System.Threading.Tasks;
6-
using Weikio.PluginFramework.Tools;
6+
using Weikio.TypeGenerator;
77

88
namespace Weikio.PluginFramework.Catalogs.Roslyn
99
{
@@ -60,7 +60,7 @@ public Task<Assembly> CreateAssembly()
6060
code.AppendLine(_code);
6161
var assemblySourceCode = code.ToString();
6262

63-
var result = generator.Generate(assemblySourceCode);
63+
var result = generator.GenerateAssembly(assemblySourceCode);
6464

6565
return Task.FromResult(result);
6666
}

src/Weikio.PluginFramework.Catalogs.Roslyn/RoslynPluginCatalogOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Version PluginVersion
2727
set
2828
{
2929
_pluginVersion = value;
30-
30+
3131
PluginNameOptions.PluginVersionGenerator = (options, type) => _pluginVersion;
3232
}
3333
}

src/Weikio.PluginFramework.Catalogs.Roslyn/ScriptInitializer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Microsoft.CodeAnalysis.CSharp.Scripting;
1010
using Microsoft.CodeAnalysis.CSharp.Syntax;
1111
using Microsoft.CodeAnalysis.Scripting;
12-
using Weikio.PluginFramework.Tools;
12+
using Weikio.TypeGenerator;
1313

1414
namespace Weikio.PluginFramework.Catalogs.Roslyn
1515
{
@@ -67,6 +67,8 @@ public async Task<Assembly> CreateAssembly()
6767
code.AppendLine("using System.Text;");
6868
code.AppendLine("using System.Collections;");
6969
code.AppendLine("using System.Collections.Generic;");
70+
code.AppendLine("using System.Reflection;");
71+
code.AppendLine("[assembly: AssemblyFileVersion(\"1.0.0.0\")]");
7072

7173
if (_options.AdditionalNamespaces?.Any() == true)
7274
{
@@ -111,7 +113,7 @@ public async Task<Assembly> CreateAssembly()
111113

112114
var assemblySourceCode = code.ToString();
113115

114-
var result = generator.Generate(assemblySourceCode);
116+
var result = generator.GenerateAssembly(assemblySourceCode);
115117

116118
return result;
117119
}

src/Weikio.PluginFramework.Catalogs.Roslyn/Weikio.PluginFramework.Catalogs.Roslyn.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="MinVer" Version="2.0.*" />
19-
<PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.6.0"/>
20-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.6.0"/>
19+
<PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.6.0" />
20+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.6.0" />
21+
<PackageReference Include="Weikio.TypeGenerator" Version="1.2.4" />
2122
</ItemGroup>
2223

2324
<ItemGroup>

src/Weikio.PluginFramework/Catalogs/Delegates/CustomAssemblyLoadContext.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Weikio.PluginFramework/Catalogs/Delegates/DelegateCache.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Weikio.PluginFramework/Catalogs/Delegates/DelegateCatalog.cs

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
using System.Threading.Tasks;
55
using Weikio.PluginFramework.Abstractions;
66
using Weikio.PluginFramework.TypeFinding;
7+
using Weikio.TypeGenerator;
8+
using Weikio.TypeGenerator.Delegates;
79

810
namespace Weikio.PluginFramework.Catalogs.Delegates
911
{
1012
public class DelegatePluginCatalog : IPluginCatalog
1113
{
12-
private AssemblyPluginCatalog _catalog;
14+
private TypePluginCatalog _catalog;
1315
private readonly MulticastDelegate _multicastDelegate;
1416

1517
private readonly DelegatePluginCatalogOptions _options;
1618

1719
public DelegatePluginCatalog(MulticastDelegate multicastDelegate) : this(multicastDelegate, pluginName: null)
1820
{
1921
}
22+
2023
/// <summary>
2124
/// Creates an instance of DelegatePluginCatalog
2225
/// </summary>
@@ -26,7 +29,7 @@ public DelegatePluginCatalog(MulticastDelegate multicastDelegate, string pluginN
2629
{
2730
}
2831

29-
public DelegatePluginCatalog(MulticastDelegate multicastDelegate, DelegatePluginCatalogOptions options) : this(multicastDelegate,
32+
public DelegatePluginCatalog(MulticastDelegate multicastDelegate, DelegatePluginCatalogOptions options) : this(multicastDelegate,
3033
options?.ConversionRules, options?.NameOptions, options)
3134
{
3235
}
@@ -73,10 +76,14 @@ public DelegatePluginCatalog(MulticastDelegate multicastDelegate,
7376

7477
public async Task Initialize()
7578
{
76-
var converter = new DelegateToAssemblyConverter();
77-
var assembly = converter.CreateAssembly(_multicastDelegate, _options);
79+
var converter = new DelegateToTypeWrapper();
80+
81+
// Convert this catalog's options to the format supported by Delegate Wrapper.
82+
// TODO: At some good point change the catalog so that it uses the Delegate Wrapper's options instead of defining its own.
83+
var delegateToTypeWrapperOptions = ConvertOptions();
84+
var assembly = converter.CreateType(_multicastDelegate, delegateToTypeWrapperOptions);
7885

79-
var options = new AssemblyPluginCatalogOptions() { PluginNameOptions = _options.NameOptions };
86+
var options = new TypePluginCatalogOptions() { PluginNameOptions = _options.NameOptions };
8087

8188
if (_options.Tags?.Any() == true)
8289
{
@@ -85,13 +92,51 @@ public async Task Initialize()
8592
TypeFinderCriterias = new List<TypeFinderCriteria> { TypeFinderCriteriaBuilder.Create().Tag(_options.Tags.ToArray()) }
8693
};
8794
}
88-
89-
_catalog = new AssemblyPluginCatalog(assembly, options);
95+
96+
_catalog = new TypePluginCatalog(assembly, options);
9097
await _catalog.Initialize();
9198

9299
IsInitialized = true;
93100
}
94101

102+
private DelegateToTypeWrapperOptions ConvertOptions()
103+
{
104+
var convRules = GetConversionRules();
105+
106+
return new DelegateToTypeWrapperOptions()
107+
{
108+
ConversionRules = convRules,
109+
MethodName = _options.MethodName,
110+
NamespaceName = _options.NamespaceName,
111+
TypeName = _options.TypeName,
112+
MethodNameGenerator = wrapperOptions => _options.MethodNameGenerator(_options),
113+
NamespaceNameGenerator = wrapperOptions => _options.NamespaceNameGenerator(_options),
114+
TypeNameGenerator = wrapperOptions => _options.TypeNameGenerator(_options),
115+
};
116+
}
117+
118+
private List<ParameterConversionRule> GetConversionRules()
119+
{
120+
var convRules = new List<ParameterConversionRule>();
121+
122+
foreach (var conversionRule in _options.ConversionRules)
123+
{
124+
var paramConversion = new ParameterConversionRule(conversionRule.CanHandle, info =>
125+
{
126+
var handleResult = conversionRule.Handle(info);
127+
128+
return new TypeGenerator.ParameterConversion()
129+
{
130+
Name = handleResult.Name, ToConstructor = handleResult.ToConstructor, ToPublicProperty = handleResult.ToPublicProperty
131+
};
132+
});
133+
134+
convRules.Add(paramConversion);
135+
}
136+
137+
return convRules;
138+
}
139+
95140
public bool IsInitialized { get; set; }
96141

97142
public List<Plugin> GetPlugins()

0 commit comments

Comments
 (0)