simplified Help_GetAppConfig access to Json values

This commit is contained in:
Wizou 2021-11-13 15:09:28 +01:00
parent 7ed21d5af4
commit f901319ca4
3 changed files with 60 additions and 12 deletions

View file

@ -1224,6 +1224,7 @@ namespace WTelegram
int fileOffset = 0, maxOffsetSeen = 0;
long transmitted = 0;
var tasks = new Dictionary<int, Task>();
progress?.Invoke(0, fileSize);
bool abort = false;
while (!abort)
{

View file

@ -367,10 +367,27 @@ namespace TL
}
partial class JsonObjectValue { public override string ToString() => $"{HttpUtility.JavaScriptStringEncode(key, true)}:{value}"; }
partial class JsonNull { public override string ToString() => "null"; }
partial class JsonBool { public override string ToString() => value ? "true" : "false"; }
partial class JsonNumber { public override string ToString() => value.ToString(CultureInfo.InvariantCulture); }
partial class JsonString { public override string ToString() => HttpUtility.JavaScriptStringEncode(value, true); }
partial class JSONValue { public abstract object ToNative(); }
partial class JsonNull
{
public override string ToString() => "null";
public override object ToNative() => null;
}
partial class JsonBool
{
public override string ToString() => value ? "true" : "false";
public override object ToNative() => value;
}
partial class JsonNumber
{
public override string ToString() => value.ToString(CultureInfo.InvariantCulture);
public override object ToNative() => value;
}
partial class JsonString
{
public override string ToString() => HttpUtility.JavaScriptStringEncode(value, true);
public override object ToNative() => value;
}
partial class JsonArray
{
public override string ToString()
@ -380,6 +397,22 @@ namespace TL
sb.Append(i == 0 ? "" : ",").Append(value[i]);
return sb.Append(']').ToString();
}
public object[] ToNativeArray() => value.Select(v => v.ToNative()).ToArray();
public override object ToNative()
{
if (value.Length == 0) return Array.Empty<object>();
var first = value[0].ToNative();
var elementType = first.GetType();
var array = Array.CreateInstance(elementType, value.Length);
array.SetValue(first, 0);
for (int i = 1; i < value.Length; i++)
{
var elem = value[i].ToNative();
if (elem.GetType() != elementType) return ToNativeArray();
array.SetValue(elem, i);
}
return array;
}
}
partial class JsonObject
{
@ -390,6 +423,22 @@ namespace TL
sb.Append(i == 0 ? "" : ",").Append(value[i]);
return sb.Append('}').ToString();
}
public Dictionary<string, object> ToDictionary() => value.ToDictionary(v => v.key, v => v.value.ToNative());
public override object ToNative()
{
if (value.Length == 0) return new Dictionary<string, object>();
var first = value[0].value.ToNative();
var elementType = first.GetType();
var dic = Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(typeof(string), elementType)) as System.Collections.IDictionary;
dic.Add(value[0].key, first);
for (int i = 1; i < value.Length; i++)
{
var elem = value[i].value.ToNative();
if (elem.GetType() != elementType) return ToDictionary();
dic.Add(value[i].key, elem);
}
return dic;
}
}
public static class Markdown

View file

@ -10070,11 +10070,9 @@ namespace TL
public JSONValue data;
}
/// <summary>JSON key: value pair <para>Derived classes: <see cref="JsonObjectValue"/></para> <para>See <a href="https://corefork.telegram.org/type/JSONObjectValue"/></para></summary>
public abstract class JSONObjectValue : IObject { }
/// <summary>JSON key: value pair <para>See <a href="https://corefork.telegram.org/constructor/jsonObjectValue"/></para></summary>
[TLDef(0xC0DE1BD9)]
public partial class JsonObjectValue : JSONObjectValue
public partial class JsonObjectValue : IObject
{
/// <summary>Key</summary>
public string key;
@ -10083,7 +10081,7 @@ namespace TL
}
/// <summary>JSON value <para>Derived classes: <see cref="JsonNull"/>, <see cref="JsonBool"/>, <see cref="JsonNumber"/>, <see cref="JsonString"/>, <see cref="JsonArray"/>, <see cref="JsonObject"/></para> <para>See <a href="https://corefork.telegram.org/type/JSONValue"/></para></summary>
public abstract class JSONValue : IObject { }
public abstract partial class JSONValue : IObject { }
/// <summary>null JSON value <para>See <a href="https://corefork.telegram.org/constructor/jsonNull"/></para></summary>
[TLDef(0x3F6D7B68)]
public partial class JsonNull : JSONValue { }
@ -10120,7 +10118,7 @@ namespace TL
public partial class JsonObject : JSONValue
{
/// <summary>Values</summary>
public JSONObjectValue[] value;
public JsonObjectValue[] value;
}
/// <summary>Table cell <para>See <a href="https://corefork.telegram.org/constructor/pageTableCell"/></para></summary>
@ -10475,7 +10473,7 @@ namespace TL
send_inline = 0x40,
/// <summary>If set, does not allow a user to embed links in the messages of a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a></summary>
embed_links = 0x80,
/// <summary>If set, does not allow a user to send stickers in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a></summary>
/// <summary>If set, does not allow a user to send polls in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a></summary>
send_polls = 0x100,
/// <summary>If set, does not allow any user to change the description of a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a></summary>
change_info = 0x400,
@ -15075,7 +15073,7 @@ namespace TL
path = path,
});
/// <summary>Get app-specific configuration, see <a href="https://corefork.telegram.org/api/config#client-configuration">client configuration</a> for more info on the result. <para>See <a href="https://corefork.telegram.org/method/help.getAppConfig"/></para></summary>
public static Task<JSONValue> Help_GetAppConfig(this Client client)
public static Task<JsonObject> Help_GetAppConfig(this Client client)
=> client.CallAsync(new Help_GetAppConfig
{
});
@ -18718,7 +18716,7 @@ namespace TL.Methods
}
[TLDef(0x98914110)]
public class Help_GetAppConfig : IMethod<JSONValue> { }
public class Help_GetAppConfig : IMethod<JsonObject> { }
[TLDef(0x6F02F748)]
public class Help_SaveAppLog : IMethod<bool>