修改代码
This commit is contained in:
parent
ff517664fe
commit
c47ee94469
@ -157,6 +157,7 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
||||
code.AppendLine("// <auto-generated/>");
|
||||
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()};");
|
||||
@ -199,6 +200,13 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
||||
//生成当前类属性名称集合
|
||||
GeneratePropertyListForSourceEntity(propList, code, compilation, classSymbol);
|
||||
|
||||
//生成当前类属性信息集合
|
||||
GeneratePropertyInfoListForSourceEntity(
|
||||
propList,
|
||||
code,
|
||||
compilation,
|
||||
classSymbol);
|
||||
|
||||
|
||||
//生成当前类属性访问
|
||||
GetGeneratePropertyValueForSourceEntity(
|
||||
@ -214,8 +222,6 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
||||
compilation,
|
||||
classSymbol);
|
||||
|
||||
|
||||
|
||||
code.AppendLine("}");
|
||||
return code.ToString();
|
||||
}
|
||||
@ -468,5 +474,42 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
||||
|
||||
code.AppendLine(" };");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成当前类属性信息集合
|
||||
/// </summary>
|
||||
/// <param name="propList">属性集合</param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="compilation"></param>
|
||||
/// <param name="classSymbol"></param>
|
||||
private static void GeneratePropertyInfoListForSourceEntity(
|
||||
IEnumerable<IPropertySymbol> propList,
|
||||
StringBuilder code,
|
||||
Compilation compilation,
|
||||
INamedTypeSymbol classSymbol)
|
||||
{
|
||||
code.AppendLine(" public List<string> PropertyList {get;} = new List<string>()");
|
||||
code.AppendLine(" {");
|
||||
List<string> tempPropList = new List<string>();
|
||||
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(" };");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ public sealed class TableModelSingleMeasuringEntityAccessor3<T> : 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<string> PropertyList { get; } = new List<string>()
|
||||
public List<string> PropertyNameList { get; } = new List<string>()
|
||||
{
|
||||
"SingleColumn.Item1","SingleColumn.Item2","SystemName","ProjectId","DeviceType","DeviceId","Timestamps" };
|
||||
public object GetPropertyValue(JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T> targetEntity, string propertyName)
|
||||
|
||||
@ -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
|
||||
/// <summary>
|
||||
/// 属性名称集合
|
||||
/// </summary>
|
||||
List<string> PropertyList { get; }
|
||||
List<string> PropertyNameList { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 属性信息集合
|
||||
/// </summary>
|
||||
List<PropertyInfo> PropertyInfoList { get; }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user