Compare commits
No commits in common. "b6d2c7148d02e71d180373ade624ce6e8bb72770" and "42061493dc9312bf90713a31859366711cac17a2" have entirely different histories.
b6d2c7148d
...
42061493dc
@ -4,9 +4,6 @@
|
|||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AssemblyVersion>1.0.1</AssemblyVersion>
|
|
||||||
<FileVersion>1.0.1</FileVersion>
|
|
||||||
<Version>1.0.1</Version>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Apache.IoTDB" />
|
<PackageReference Include="Apache.IoTDB" />
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
|
using JiShe.CollectBus.Common.Extensions;
|
||||||
|
using JiShe.CollectBus.Common.Helpers;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Options
|
namespace JiShe.CollectBus.IoTDB.Options
|
||||||
{
|
{
|
||||||
|
|||||||
@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace JiShe.CollectBus.Analyzers.Shared;
|
||||||
|
|
||||||
|
public static class SourceEntityAccessorFactory3
|
||||||
|
{
|
||||||
|
private static readonly ConcurrentDictionary<Type, object> _accessors = new();
|
||||||
|
|
||||||
|
public static ISourceEntityAccessor<T> GetAccessor<T>()
|
||||||
|
{
|
||||||
|
return (ISourceEntityAccessor<T>)_accessors.GetOrAdd(typeof(T), t =>
|
||||||
|
{
|
||||||
|
// 获取泛型类型定义信息(如果是泛型类型)
|
||||||
|
var isGeneric = t.IsGenericType;
|
||||||
|
var genericTypeDef = isGeneric ? t.GetGenericTypeDefinition() : null;
|
||||||
|
var arity = isGeneric ? genericTypeDef!.GetGenericArguments().Length : 0;
|
||||||
|
|
||||||
|
// 构建访问器类名
|
||||||
|
var typeName = isGeneric
|
||||||
|
? $"{t.Namespace}.{genericTypeDef!.Name.Split('`')[0]}Accessor`{arity}"
|
||||||
|
: $"{t.Namespace}.{t.Name}Accessor";
|
||||||
|
|
||||||
|
// 尝试从当前程序集加载
|
||||||
|
var accessorType = Assembly.GetAssembly(t)!.GetType(typeName)
|
||||||
|
?? throw new InvalidOperationException($"Accessor type {typeName} not found");
|
||||||
|
|
||||||
|
// 处理泛型参数
|
||||||
|
if (isGeneric && accessorType.IsGenericTypeDefinition)
|
||||||
|
{
|
||||||
|
accessorType = accessorType.MakeGenericType(t.GetGenericArguments());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Activator.CreateInstance(accessorType)!;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object GetAccessor(Type type)
|
||||||
|
{
|
||||||
|
MethodInfo getAccessorMethod = typeof(SourceEntityAccessorFactory)
|
||||||
|
.GetMethod(
|
||||||
|
name: nameof(GetAccessor),
|
||||||
|
bindingAttr: BindingFlags.Public | BindingFlags.Static,
|
||||||
|
|
||||||
|
types: Type.EmptyTypes
|
||||||
|
);
|
||||||
|
|
||||||
|
MethodInfo genericMethod = getAccessorMethod.MakeGenericMethod(type);
|
||||||
|
return genericMethod.Invoke(null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,9 +4,6 @@
|
|||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AssemblyVersion>1.0.1</AssemblyVersion>
|
|
||||||
<FileVersion>1.0.1</FileVersion>
|
|
||||||
<Version>1.0.1</Version>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user