mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
fix #242: correctly handle UserEmpty in ReadTLDictionary
This commit is contained in:
parent
abeed476e7
commit
f3ca76bb8f
|
|
@ -208,7 +208,7 @@ public class MTProtoGenerator : IIncrementalGenerator
|
|||
|
||||
foreach (var nullable in nullables)
|
||||
makeTL.AppendLine($"\t\t\t0x{nullable.Value:X8} => null,");
|
||||
makeTL.AppendLine("\t\t\tvar ctorNb => throw new Exception($\"Cannot find type for ctor #{ctorNb:x}\")");
|
||||
makeTL.AppendLine("\t\t\tvar ctorNb => throw new WTelegram.WTException($\"Cannot find type for ctor #{ctorNb:x}\")");
|
||||
makeTL.AppendLine("\t\t};");
|
||||
namespaces["TL"]["Layer"] = makeTL.ToString();
|
||||
foreach (var namesp in namespaces)
|
||||
|
|
|
|||
|
|
@ -267,9 +267,7 @@ namespace WTelegram
|
|||
|
||||
public class WTException : ApplicationException
|
||||
{
|
||||
public readonly int ErrorCode;
|
||||
public WTException(string message) : base(message) { }
|
||||
public WTException(string message, int code) : base(message) => ErrorCode = code;
|
||||
public WTException(string message, Exception innerException) : base(message, innerException) { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/TL.cs
10
src/TL.cs
|
|
@ -32,9 +32,9 @@ namespace TL
|
|||
public readonly int Bit = bit;
|
||||
}
|
||||
|
||||
public sealed class RpcException(int code, string message, int x = -1) : WTelegram.WTException(message, code)
|
||||
public sealed class RpcException(int code, string message, int x = -1) : WTelegram.WTException(message)
|
||||
{
|
||||
public int Code => ErrorCode;
|
||||
public readonly int Code = code;
|
||||
/// <summary>The value of X in the message, -1 if no variable X was found</summary>
|
||||
public readonly int X = x;
|
||||
public override string ToString() { var str = base.ToString(); return str.Insert(str.IndexOf(':') + 1, " " + Code); }
|
||||
|
|
@ -278,8 +278,10 @@ namespace TL
|
|||
var dict = new Dictionary<long, T>(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var value = (T)reader.ReadTLObject();
|
||||
dict[value.ID] = value is UserEmpty ? null : value;
|
||||
var obj = reader.ReadTLObject();
|
||||
if (obj is T value) dict[value.ID] = value;
|
||||
else if (obj is UserEmpty ue) dict[ue.id] = null;
|
||||
else throw new InvalidCastException($"ReadTLDictionary got '{obj?.GetType().Name}' instead of '{typeof(T).Name}'");
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue