Пример #1
0
        public static new VkDocumentAttachment FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkDocumentAttachment();

            result.Id      = (long)json["id"];
            result.OwnerId = (long)json["owner_id"];

            if (json["title"] != null)
            {
                result.Title = (string)json["title"];
            }

            if (json["size"] != null)
            {
                result.Size = long.Parse((string)json["size"]);
            }

            if (json["ext"] != null)
            {
                result.Ext = (string)json["ext"];
            }

            if (json["url"] != null)
            {
                result.Url = (string)json["url"];
            }

            if (json["photo_100"] != null)
            {
                result.Photo100 = (string)json["photo_100"];
            }

            if (json["photo_130"] != null)
            {
                result.Photo130 = (string)json["photo_130"];
            }

            if (json["date"] != null)
            {
                result.Date = DateTimeExtensions.UnixTimeStampToDateTime((double)json["date"]);
            }

            if (json["type"] != null)
            {
                result.DocumentType = (int)json["type"];
            }

            return(result);
        }
Пример #2
0
        public static List <VkAttachment> FromJson(JToken json)
        {
            var result = new List <VkAttachment>();

            foreach (var a in json)
            {
                switch (a["type"].Value <string>())
                {
                case "audio":
                    result.Add(VkAudioAttachment.FromJson(a["audio"]));
                    break;

                case "photo":
                    result.Add(VkPhotoAttachment.FromJson(a["photo"]));
                    break;

                case "sticker":
                    result.Add(VkStickerAttachment.FromJson(a["sticker"]));
                    break;

                case "gift":
                    result.Add(VkGiftAttachment.FromJson(a["gift"]));
                    break;

                case "link":
                    result.Add(VkLinkAttachment.FromJson(a["link"]));
                    break;

                case "doc":
                    result.Add(VkDocumentAttachment.FromJson(a["doc"]));
                    break;

                case "video":
                    result.Add(VkVideoAttachment.FromJson(a["video"]));
                    break;

                case "wall":
                    result.Add(VkWallPostAttachment.FromJson(a["wall"]));
                    break;
                }
            }

            return(result);
        }