From c47ee9446900e4f2c76baa3ec64fc522c6a35220 Mon Sep 17 00:00:00 2001
From: ChenYi <296215406@outlook.com>
Date: Wed, 7 May 2025 17:27:37 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ComplexTypeSourceAnalyzers.cs | 51 +++++++++++++++++--
...TableModelSingleMeasuringEntityAccessor.cs | 2 +-
.../ISourceEntityAccessor.cs | 8 ++-
3 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs b/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs
index 195175a..ea0ef13 100644
--- a/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs
+++ b/modules/JiShe.CollectBus.Analyzers/ComplexTypeSourceAnalyzers.cs
@@ -157,6 +157,7 @@ namespace JiShe.CollectBus.IncrementalGenerator
code.AppendLine("// ");
code.AppendLine("#nullable enable");
code.AppendLine("using System;");
+ code.AppendLine("using System.Reflection;");
code.AppendLine("using System.Collections.Generic;");
code.AppendLine("using JiShe.CollectBus.Analyzers.Shared;");
code.AppendLine($"namespace {classSymbol.ContainingNamespace.ToDisplayString()};");
@@ -198,7 +199,14 @@ namespace JiShe.CollectBus.IncrementalGenerator
//生成当前类属性名称集合
GeneratePropertyListForSourceEntity(propList, code, compilation, classSymbol);
-
+
+ //生成当前类属性信息集合
+ GeneratePropertyInfoListForSourceEntity(
+ propList,
+ code,
+ compilation,
+ classSymbol);
+
//生成当前类属性访问
GetGeneratePropertyValueForSourceEntity(
@@ -213,9 +221,7 @@ namespace JiShe.CollectBus.IncrementalGenerator
code,
compilation,
classSymbol);
-
-
-
+
code.AppendLine("}");
return code.ToString();
}
@@ -468,5 +474,42 @@ namespace JiShe.CollectBus.IncrementalGenerator
code.AppendLine(" };");
}
+
+
+ ///
+ /// 生成当前类属性信息集合
+ ///
+ /// 属性集合
+ ///
+ ///
+ ///
+ private static void GeneratePropertyInfoListForSourceEntity(
+ IEnumerable propList,
+ StringBuilder code,
+ Compilation compilation,
+ INamedTypeSymbol classSymbol)
+ {
+ code.AppendLine(" public List PropertyList {get;} = new List()");
+ code.AppendLine(" {");
+ List tempPropList = new List();
+ foreach (var prop in propList)
+ {
+ if (prop.Type is INamedTypeSymbol { IsTupleType: true } tupleType)
+ {
+ foreach (var element in tupleType.TupleElements)
+ {
+ tempPropList.Add($"\"{prop.Name}.{element.Name}\"");
+ }
+ }
+ else
+ {
+ tempPropList.Add($"\"{prop.Name}\"");
+ }
+ }
+
+ code.Append(string.Join(",", tempPropList));
+
+ code.AppendLine(" };");
+ }
}
}
\ No newline at end of file
diff --git a/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntityAccessor.cs b/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntityAccessor.cs
index 9c9c773..e0bedd4 100644
--- a/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntityAccessor.cs
+++ b/modules/JiShe.CollectBus.IoTDB/Model/TableModelSingleMeasuringEntityAccessor.cs
@@ -21,7 +21,7 @@ public sealed class TableModelSingleMeasuringEntityAccessor3 : ISourceEntityA
public static void SetDeviceId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.DeviceId = value;
public static long GetTimestamps(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.Timestamps;
public static void SetTimestamps(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, long value) => obj.Timestamps = value;
- public List PropertyList { get; } = new List()
+ public List PropertyNameList { get; } = new List()
{
"SingleColumn.Item1","SingleColumn.Item2","SystemName","ProjectId","DeviceType","DeviceId","Timestamps" };
public object GetPropertyValue(JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity targetEntity, string propertyName)
diff --git a/shared/JiShe.CollectBus.Analyzers.Shared/ISourceEntityAccessor.cs b/shared/JiShe.CollectBus.Analyzers.Shared/ISourceEntityAccessor.cs
index baff180..5e67826 100644
--- a/shared/JiShe.CollectBus.Analyzers.Shared/ISourceEntityAccessor.cs
+++ b/shared/JiShe.CollectBus.Analyzers.Shared/ISourceEntityAccessor.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Reflection;
using System.Text;
namespace JiShe.CollectBus.Analyzers.Shared
@@ -25,6 +26,11 @@ namespace JiShe.CollectBus.Analyzers.Shared
///
/// 属性名称集合
///
- List PropertyList { get; }
+ List PropertyNameList { get; }
+
+ ///
+ /// 属性信息集合
+ ///
+ List PropertyInfoList { get; }
}
}