fix (uint) unboxing on fields "int flags" (improved)

This commit is contained in:
Wizou 2022-02-06 23:22:51 +01:00
parent bedb44582e
commit 8bbb753c32
2 changed files with 6 additions and 4 deletions

View file

@ -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;

View file

@ -46,7 +46,7 @@ namespace TL
if (((ifFlag = field.GetCustomAttribute<IfFlagAttribute>()) != 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<IfFlagAttribute>()) != 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;
}