-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1507 добавляет GroupIdConverter, SecretConverter, UpdateTypeConverte…
…r, обновляет GroupUpdatesConverter для поддержки Callback API (#1508) * "#1507 добавляет CallbackGroupUpdatesConverter, GroupIdConverter, SecretConverter, UpdateTypeConverter" * #1507 Заставить работать и для LongPoll * Мелкие изменения
- Loading branch information
Showing
6 changed files
with
137 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using VkNet.Model.GroupUpdate; | ||
|
||
namespace VkNet.Utils.JsonConverter; | ||
|
||
/// <inheritdoc /> | ||
public class GroupIdConverter : JsonConverter<GroupId> | ||
{ | ||
/// <inheritdoc /> | ||
public override GroupId ReadJson(JsonReader reader, Type objectType, GroupId existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.Value == null) | ||
return null; | ||
|
||
var id = Convert.ToUInt64(reader.Value); | ||
return new GroupId(id); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void WriteJson(JsonWriter writer, GroupId value, JsonSerializer serializer) | ||
{ | ||
writer.WriteValue(value?.Value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using VkNet.Model.GroupUpdate; | ||
|
||
namespace VkNet.Utils.JsonConverter; | ||
|
||
/// <inheritdoc /> | ||
public class SecretConverter : JsonConverter<Secret> | ||
{ | ||
/// <inheritdoc /> | ||
public override Secret ReadJson(JsonReader reader, Type objectType, Secret existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.Value == null) | ||
return null; | ||
|
||
return new Secret(reader.Value.ToString()); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void WriteJson(JsonWriter writer, Secret value, JsonSerializer serializer) | ||
{ | ||
writer.WriteValue(value?.Value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Globalization; | ||
using VkNet.Enums.SafetyEnums; | ||
using VkNet.Model.GroupUpdate; | ||
|
||
namespace VkNet.Utils.JsonConverter; | ||
|
||
/// <inheritdoc /> | ||
public class UpdateTypeConverter : JsonConverter<UpdateType> | ||
{ | ||
/// <inheritdoc /> | ||
public override UpdateType ReadJson(JsonReader reader, Type objectType, UpdateType existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.Value == null) | ||
return null; | ||
|
||
var info = CultureInfo.CurrentCulture.TextInfo; | ||
|
||
var groupUpdateTypeStr = reader.Value.ToString().ToLower().Replace("_", " "); | ||
groupUpdateTypeStr = info.ToTitleCase(groupUpdateTypeStr).Replace(" ", string.Empty); | ||
|
||
return new UpdateType(Utilities.Deserialize<GroupUpdateType>(groupUpdateTypeStr).Value); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void WriteJson(JsonWriter writer, UpdateType value, JsonSerializer serializer) | ||
{ | ||
writer.WriteValue(value?.Value); | ||
} | ||
} |