Code optimization and controller enchancement
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Modbus.Net.CodeGenerator
|
||||
{
|
||||
[Generator]
|
||||
public class DatabaseWriteEntityCodeGenerator : ISourceGenerator
|
||||
{
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
var content = "";
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
content += $@"public double? Value{i} {{ get; set; }}
|
||||
";
|
||||
}
|
||||
var source = $@"
|
||||
|
||||
namespace MachineJob
|
||||
{{
|
||||
public partial class DatabaseWriteEntity
|
||||
{{
|
||||
{content}
|
||||
}}
|
||||
}}";
|
||||
context.AddSource("DatabaseWriteContent.g.cs", source);
|
||||
}
|
||||
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
@@ -24,20 +24,11 @@ namespace MachineJob
|
||||
}
|
||||
|
||||
[Table(name: "databasewrites")]
|
||||
public class DatabaseWriteEntity
|
||||
public partial class DatabaseWriteEntity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public double? Value1 { get; set; }
|
||||
public double? Value2 { get; set; }
|
||||
public double? Value3 { get; set; }
|
||||
public double? Value4 { get; set; }
|
||||
public double? Value5 { get; set; }
|
||||
public double? Value6 { get; set; }
|
||||
public double? Value7 { get; set; }
|
||||
public double? Value8 { get; set; }
|
||||
public double? Value9 { get; set; }
|
||||
public double? Value10 { get; set; }
|
||||
|
||||
public DateTime UpdateTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +27,8 @@
|
||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.OPC\Modbus.Net.Opc.csproj" />
|
||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net.Siemens\Modbus.Net.Siemens.csproj" />
|
||||
<ProjectReference Include="..\..\Modbus.Net\Modbus.Net\Modbus.Net.csproj" />
|
||||
<ProjectReference Include="..\MachineJob.CodeGenerator\MachineJob.CodeGenerator.csproj"
|
||||
OutputItemType="Analyzer"
|
||||
ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user