From 8bbb753c32318d0242d745601647d691d2ff5e86 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sun, 6 Feb 2022 23:22:51 +0100 Subject: [PATCH] fix (uint) unboxing on fields "int flags" (improved) --- src/Client.cs | 4 +++- src/TL.cs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Client.cs b/src/Client.cs index c8bcd3a..f19d306 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -1202,10 +1202,12 @@ namespace WTelegram lock (_accessHashes) _accessHashes.GetOrCreate(typeof(T))[id] = access_hash; } - internal void UpdateAccessHash(object obj, Type type, object access_hash) + internal void MonitorField(FieldInfo fieldInfo, object obj, object access_hash) { if (!CollectAccessHash) return; + if (fieldInfo.Name != "access_hash") return; if (access_hash is not long accessHash) return; + var type = fieldInfo.ReflectedType; if (type.GetField("id") is not FieldInfo idField) return; if (idField.GetValue(obj) is not long id) if (idField.GetValue(obj) is not int idInt) return; diff --git a/src/TL.cs b/src/TL.cs index 6dff413..b7395bc 100644 --- a/src/TL.cs +++ b/src/TL.cs @@ -46,7 +46,7 @@ namespace TL if (((ifFlag = field.GetCustomAttribute()) != null) && (flags & (1U << ifFlag.Bit)) == 0) continue; object value = field.GetValue(obj); writer.WriteTLValue(value, field.FieldType); - if (field.Name == "flags" && field.FieldType.IsEnum) flags = (uint)value; + if (field.FieldType.IsEnum && field.Name == "flags") flags = (uint)value; } } @@ -70,8 +70,8 @@ namespace TL if (((ifFlag = field.GetCustomAttribute()) != null) && (flags & (1U << ifFlag.Bit)) == 0) continue; object value = reader.ReadTLValue(field.FieldType); field.SetValue(obj, value); - if (field.Name == "flags" && field.FieldType.IsEnum) flags = (uint)value; - else if (field.Name == "access_hash") reader.Client?.UpdateAccessHash(obj, type, value); + if (field.FieldType.IsEnum && field.Name == "flags") flags = (uint)value; + reader.Client?.MonitorField(field, obj, value); } return (IObject)obj; }