Пример #1
0
        internal static ChannelObject FromJObject(JObject jObj)
        {
            var result = new ChannelObject();

            result._data = JsonHelpers.FromJObject(result, jObj);

            var mbrs = result._data.GetData <JArray>("members");

            if (mbrs != null)
            {
                var members = new List <ChannelMember>();
                foreach (var mbr in mbrs)
                {
                    var memberObj = mbr as JObject;
                    members.Add(ChannelMember.FromJObject(memberObj));
                }
                result.Members = members;
                result._data.RemoveData("members");
            }

            var userObj = result._data.GetData <JObject>("created_by");

            if (userObj != null)
            {
                result.CreatedBy = User.FromJObject(userObj);
                result._data.RemoveData("created_by");
            }

            return(result);
        }
Пример #2
0
        public static Event FromJObject(JObject jObj)
        {
            var result = new Event();

            result._data = JsonHelpers.FromJObject(result, jObj);

            var msgObj = result._data.GetData <JObject>("message");

            if (msgObj != null)
            {
                result.Message = Message.FromJObject(msgObj);
                result._data.RemoveData("message");
            }
            var reactionObj = result._data.GetData <JObject>("reaction");

            if (reactionObj != null)
            {
                result.Reaction = Reaction.FromJObject(reactionObj);
                result._data.RemoveData("reaction");
            }
            var chanObj = result._data.GetData <JObject>("channel");

            if (chanObj != null)
            {
                result.Channel = ChannelObject.FromJObject(chanObj);
                result._data.RemoveData("channel");
            }
            var memberObj = result._data.GetData <JObject>("member");

            if (memberObj != null)
            {
                result.Member = ChannelMember.FromJObject(memberObj);
                result._data.RemoveData("member");
            }
            var userObj = result._data.GetData <JObject>("user");

            if (userObj != null)
            {
                result.User = User.FromJObject(userObj);
                result._data.RemoveData("user");
            }
            userObj = result._data.GetData <JObject>("me");
            if (userObj != null)
            {
                result.OwnUser = User.FromJObject(userObj);
                result._data.RemoveData("me");
            }

            return(result);
        }