Use SimplifiedFullName for type validation.

This commit is contained in:
Ahmed Yasin Koculu
2024-08-24 03:00:00 +02:00
parent dbcd5faa0d
commit 0bdc98c2de
4 changed files with 56 additions and 18 deletions
+37
View File
@@ -0,0 +1,37 @@
using System.Text;
namespace Tenray.ZoneTree.Core;
public static class TypeExtensions
{
public static string SimplifiedFullName(this Type type)
{
if (!type.IsGenericType)
return type.FullName;
var builder = new StringBuilder();
var typeName = type.Namespace + "." + type.Name;
int index = typeName.IndexOf('`');
if (index > 0)
{
builder.Append(typeName.Substring(0, index));
}
else
{
builder.Append(typeName);
}
builder.Append("<");
var genericArguments = type.GetGenericArguments();
var len = genericArguments.Length;
for (var i = 0; i < len; i++)
{
if (i > 0)
{
builder.Append(", ");
}
builder.Append(genericArguments[i].SimplifiedFullName());
}
builder.Append(">");
return builder.ToString();
}
}
+5 -5
View File
@@ -185,11 +185,11 @@ public sealed partial class ZoneTree<TKey, TValue> : IZoneTree<TKey, TValue>, IZ
{
if (MutableSegment != null)
ZoneTreeMeta.MutableSegment = MutableSegment.SegmentId;
ZoneTreeMeta.ComparerType = Options.Comparer.GetType().FullName;
ZoneTreeMeta.KeyType = typeof(TKey).FullName;
ZoneTreeMeta.ValueType = typeof(TValue).FullName;
ZoneTreeMeta.KeySerializerType = Options.KeySerializer.GetType().FullName;
ZoneTreeMeta.ValueSerializerType = Options.ValueSerializer.GetType().FullName;
ZoneTreeMeta.ComparerType = Options.Comparer.GetType().SimplifiedFullName();
ZoneTreeMeta.KeyType = typeof(TKey).SimplifiedFullName();
ZoneTreeMeta.ValueType = typeof(TValue).SimplifiedFullName();
ZoneTreeMeta.KeySerializerType = Options.KeySerializer.GetType().SimplifiedFullName();
ZoneTreeMeta.ValueSerializerType = Options.ValueSerializer.GetType().SimplifiedFullName();
ZoneTreeMeta.DiskSegment = DiskSegment.SegmentId;
ZoneTreeMeta.ReadOnlySegments = ReadOnlySegmentQueue.Select(x => x.SegmentId).ToArray();
ZoneTreeMeta.BottomSegments = BottomSegmentQueue.Select(x => x.SegmentId).ToArray();
+12 -11
View File
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Text;
using Tenray.ZoneTree.Exceptions;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments;
@@ -54,30 +55,30 @@ public sealed class ZoneTreeLoader<TKey, TValue>
Version.Parse(version),
ZoneTreeInfo.ProductVersion);
if (!string.Equals(ZoneTreeMeta.KeyType, typeof(TKey).FullName, StringComparison.Ordinal))
if (!string.Equals(ZoneTreeMeta.KeyType, typeof(TKey).SimplifiedFullName(), StringComparison.Ordinal))
throw new TreeKeyTypeMismatchException(
ZoneTreeMeta.KeyType,
typeof(TKey).FullName);
typeof(TKey).SimplifiedFullName());
if (!string.Equals(ZoneTreeMeta.ValueType, typeof(TValue).FullName, StringComparison.Ordinal))
if (!string.Equals(ZoneTreeMeta.ValueType, typeof(TValue).SimplifiedFullName(), StringComparison.Ordinal))
throw new TreeValueTypeMismatchException(
ZoneTreeMeta.ValueType,
typeof(TValue).FullName);
typeof(TValue).SimplifiedFullName());
if (!string.Equals(ZoneTreeMeta.ComparerType, Options.Comparer.GetType().FullName, StringComparison.Ordinal))
if (!string.Equals(ZoneTreeMeta.ComparerType, Options.Comparer.GetType().SimplifiedFullName(), StringComparison.Ordinal))
throw new TreeComparerMismatchException(
ZoneTreeMeta.ComparerType,
Options.Comparer.GetType().FullName);
Options.Comparer.GetType().SimplifiedFullName());
if (!string.Equals(ZoneTreeMeta.KeySerializerType, Options.KeySerializer.GetType().FullName, StringComparison.Ordinal))
if (!string.Equals(ZoneTreeMeta.KeySerializerType, Options.KeySerializer.GetType().SimplifiedFullName(), StringComparison.Ordinal))
throw new TreeKeySerializerTypeMismatchException(
ZoneTreeMeta.KeySerializerType,
Options.KeySerializer.GetType().FullName);
Options.KeySerializer.GetType().SimplifiedFullName());
if (!string.Equals(ZoneTreeMeta.ValueSerializerType, Options.ValueSerializer.GetType().FullName, StringComparison.Ordinal))
if (!string.Equals(ZoneTreeMeta.ValueSerializerType, Options.ValueSerializer.GetType().SimplifiedFullName(), StringComparison.Ordinal))
throw new TreeValueSerializerTypeMismatchException(
ZoneTreeMeta.ValueSerializerType,
Options.ValueSerializer.GetType().FullName);
Options.ValueSerializer.GetType().SimplifiedFullName());
}
void LoadZoneTreeMetaWAL()
@@ -267,4 +268,4 @@ public sealed class ZoneTreeLoader<TKey, TValue>
ReadOnlySegments, MutableSegment, DiskSegment, BottomSegments, maximumSegmentId);
return zoneTree;
}
}
}
+2 -2
View File
@@ -5,8 +5,8 @@
<Authors>Ahmed Yasin Koculu</Authors>
<PackageId>ZoneTree</PackageId>
<Title>ZoneTree</Title>
<ProductVersion>1.7.6.0</ProductVersion>
<Version>1.7.6.0</Version>
<ProductVersion>1.7.8.0</ProductVersion>
<Version>1.7.8.0</Version>
<Authors>Ahmed Yasin Koculu</Authors>
<AssemblyTitle>ZoneTree</AssemblyTitle>
<Description>ZoneTree is a persistent, high-performance, transactional, ACID-compliant ordered key-value database for NET. It can operate in memory or on local/cloud storage.</Description>