Skip to content

Commit d7617e0

Browse files
committed
Add gen .NET Assembly feature.
1 parent e7b5f83 commit d7617e0

File tree

5 files changed

+133
-53
lines changed

5 files changed

+133
-53
lines changed

QpTestClient/CodeGen/CSharpCodeGen.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Reflection;
78
using System.Text;
89
using System.Threading.Tasks;
910

@@ -28,7 +29,7 @@ private static async Task genCSharpCode(string instructionId, string typeFullNam
2829
//如果没有属性,产生类
2930
if (schema.Properties.Count == 0)
3031
{
31-
sb.Insert(code.Length-3, $"public class {typeInfo.TypeName}{Environment.NewLine}{{{Environment.NewLine}}}");
32+
sb.Insert(code.Length-2, $"public partial class {typeInfo.TypeName}{Environment.NewLine} {{{Environment.NewLine} }}");
3233
}
3334

3435
//如果是命令请求类型
@@ -66,6 +67,9 @@ private static async Task genCSharpCode(string instructionId, string typeFullNam
6667

6768
public static async Task Generate(QpInstruction instruction, string folder)
6869
{
70+
if (!Directory.Exists(folder))
71+
Directory.CreateDirectory(folder);
72+
6973
//生成通知类代码
7074
if (instruction.NoticeInfos!=null && instruction.NoticeInfos.Length>0)
7175
{
@@ -96,7 +100,7 @@ public static async Task Generate(QpInstruction instruction, string folder)
96100
sbInstruction.AppendLine(" public static QpInstruction Instance = new QpInstruction()");
97101
sbInstruction.AppendLine(" {");
98102
sbInstruction.AppendLine(" Id = typeof(Instruction).Namespace,");
99-
sbInstruction.AppendLine($" Name = {instruction.Name},");
103+
sbInstruction.AppendLine($" Name = \"{instruction.Name}\",");
100104
if (instruction.NoticeInfos!=null && instruction.NoticeInfos.Length>0)
101105
{
102106
sbInstruction.AppendLine(" NoticeInfos = new[]");
@@ -130,6 +134,21 @@ public static async Task Generate(QpInstruction instruction, string folder)
130134
sbInstruction.AppendLine(" }");
131135
sbInstruction.AppendLine("}");
132136
File.WriteAllText(Path.Combine(folder, "Instruction.cs"), sbInstruction.ToString());
137+
var qpVersion = typeof(QpChannel).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute >().InformationalVersion;
138+
File.WriteAllText(Path.Combine(folder, instruction.Id + ".csproj"), @$"
139+
<Project Sdk=""Microsoft.NET.Sdk"">
140+
141+
<PropertyGroup>
142+
<TargetFramework>netstandard2.0</TargetFramework>
143+
</PropertyGroup>
144+
145+
<ItemGroup>
146+
<PackageReference Include=""Quick.Protocol"" Version=""{qpVersion}"" />
147+
</ItemGroup>
148+
149+
</Project>
150+
");
151+
133152
}
134153
}
135154
}

QpTestClient/MainForm.Designer.cs

Lines changed: 50 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)