Example #1
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);
        }
        public static new VkVideoAttachment FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }

            var result = new VkVideoAttachment();

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

            if (json["owner_id"] != null)
            {
                result.OwnerId = (long)json["owner_id"];
            }

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

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

            if (json["duration"] != null)
            {
                result.Duration = TimeSpan.FromSeconds((long)json["duration"]);
            }

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

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

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

            if (json["views"] != null)
            {
                result.Views = (long)json["views"];
            }

            if (json["comments"] != null)
            {
                result.Comments = (long)json["comments"];
            }

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

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

            return(result);
        }