Skip to content

Commit be09f07

Browse files
committed
improved PR to FullName usage.
1 parent abe38e4 commit be09f07

3 files changed

Lines changed: 7 additions & 16 deletions

File tree

LibSample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void Main(string[] args)
2121
//new BroadcastTest().Run();
2222
//new BenchmarkTest.TestHost().Run();
2323
//new SerializerBenchmark().Run();
24-
new SpeedBecnh().Run();
24+
//new SpeedBecnh().Run();
2525
}
2626
}
2727
}

LiteNetLib/Utils/NetPacketProcessor.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43

54
namespace LiteNetLib.Utils
65
{
@@ -16,7 +15,7 @@ public class NetPacketProcessor
1615
protected virtual ulong GetHash(Type type)
1716
{
1817
ulong hash;
19-
string typeName = GetTypeName(type);
18+
string typeName = type.FullName;
2019
if (_hashCache.TryGetValue(typeName, out hash))
2120
{
2221
return hash;
@@ -48,15 +47,6 @@ protected virtual void WriteHash(Type type, NetDataWriter writer)
4847
writer.Put(GetHash(type));
4948
}
5049

51-
public static string GetTypeName(Type t)
52-
{
53-
if (!t.IsGenericType) return t.Name;
54-
55-
var genericTypes = t.GetGenericArguments();
56-
var genericArguments = genericTypes.Aggregate("", (current, type) => current + type.Name);
57-
return t.Name + genericArguments;
58-
}
59-
6050
/// <summary>
6151
/// Register nested property type
6252
/// </summary>

LiteNetLib/Utils/NetSerializer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ private static Action<TClass, TProperty> ExtractSetDelegate<TClass, TProperty>(M
177177
private StructInfo RegisterInternal<T>()
178178
{
179179
Type t = typeof(T);
180+
string typeName = t.FullName;
180181
StructInfo info;
181-
if (_registeredTypes.TryGetValue(NetPacketProcessor.GetTypeName(t), out info))
182+
if (_registeredTypes.TryGetValue(typeName, out info))
182183
{
183184
return info;
184185
}
@@ -240,7 +241,7 @@ private StructInfo RegisterInternal<T>()
240241
}
241242
else
242243
{
243-
throw new Exception("Not supported enum underlying type: " +NetPacketProcessor.GetTypeName(underlyingType));
244+
throw new Exception("Not supported enum underlying type: " + underlyingType.Name);
244245
}
245246
}
246247
else if (propertyType == typeof(string))
@@ -470,11 +471,11 @@ private StructInfo RegisterInternal<T>()
470471
}
471472
else
472473
{
473-
throw new Exception("Unknown property type: " +NetPacketProcessor.GetTypeName(propertyType));
474+
throw new Exception("Unknown property type: " + propertyType.FullName);
474475
}
475476
}
476477
}
477-
_registeredTypes.Add(NetPacketProcessor.GetTypeName(t), info);
478+
_registeredTypes.Add(typeName, info);
478479

479480
return info;
480481
}

0 commit comments

Comments
 (0)