Beispiel #1
0
        /// <summary>
        /// transforms XML into IQueryable of User
        /// </summary>
        /// <param name="responseXml">xml with Twitter response</param>
        /// <returns>IQueryable of User</returns>
        public virtual List <T> ProcessResults(string responseXml)
        {
            XElement twitterResponse = XElement.Parse(responseXml);
            var      friendship      =
                new Friendship
            {
                Type             = Type,
                SubjectUser      = SubjectUser,
                FollowingUser    = FollowingUser,
                SourceUserID     = SourceUserID,
                SourceScreenName = SourceScreenName,
                TargetUserID     = TargetUserID,
                TargetScreenName = TargetScreenName,
                Cursor           = Cursor,
                ScreenName       = ScreenName
            };

            if (twitterResponse.Name == "relationship") // Show
            {
                friendship.SourceRelationship =
                    Relationship.CreateRelationship(twitterResponse.Element("source"));
                friendship.TargetRelationship =
                    Relationship.CreateRelationship(twitterResponse.Element("target"));
            }
            else if (twitterResponse.Name == "relationships")
            {
                friendship.Relationships =
                    (from relElem in twitterResponse.Elements("relationship")
                     select Relationship.CreateRelationship(relElem))
                    .ToList();
            }
            else if (twitterResponse.Name == "id_list") // incoming/outgoing
            {
                friendship.IDInfo = IDList.CreateIDList(twitterResponse);
            }
            else // Exists
            {
                friendship.IsFriend = bool.Parse(twitterResponse.Value);
            }

            var friendList = new List <Friendship>
            {
                friendship
            };

            return(friendList.OfType <T>().ToList());
        }
        public void IDList_Can_Serialize()
        {
            var ids = new IDList();
            var stringBuilder = new StringBuilder();

            var writer = XmlWriter.Create(stringBuilder);
            var xmlSerializer = new XmlSerializer(typeof(IDList));
            xmlSerializer.Serialize(writer, ids);
        }