PastebinAPI.Paste.FromXML C# (CSharp) 메소드

FromXML() 정적인 개인적인 메소드

static private FromXML ( System.Xml.Linq.XElement xpaste ) : Paste
xpaste System.Xml.Linq.XElement
리턴 Paste
        internal static Paste FromXML(XElement xpaste)
        {
            /* Example paste xml
            <paste>
                <paste_key>0b42rwhf</paste_key>
                <paste_date>1297953260</paste_date>
                <paste_title>javascript test</paste_title>
                <paste_size>15</paste_size>
                <paste_expire_date>1297956860</paste_expire_date>
                <paste_private>0</paste_private>
                <paste_format_long>JavaScript</paste_format_long>
                <paste_format_short>javascript</paste_format_short>
                <paste_url>http://pastebin.com/0b42rwhf</paste_url>
                <paste_hits>15</paste_hits>
            </paste>
             */
            var paste = new Paste();
            paste.Key = xpaste.Element("paste_key").Value;
            paste.CreateDate = Utills.GetDate((long)xpaste.Element("paste_date"));
            paste.Title = xpaste.Element("paste_title").Value;
            paste.Size = (int)xpaste.Element("paste_size");
            var exdate = (long)xpaste.Element("paste_expire_date");
            paste.ExpireDate = exdate != 0 ? Utills.GetDate(exdate) : paste.CreateDate;
            paste.Expiration = Expiration.FromTimeSpan(paste.ExpireDate - paste.CreateDate);
            paste.Visibility = (Visibility)(int)xpaste.Element("paste_private");
            paste.Language = Language.Parse(xpaste.Element("paste_format_short").Value);
            paste.Url = xpaste.Element("paste_url").Value;
            paste.Hits = (int)xpaste.Element("paste_hits");
            return paste;
        }

Usage Example

예제 #1
0
 public static IEnumerable <Paste> PastesFromXML(string xml)
 {
     foreach (var paste in XElement.Parse("<pastes>" + xml + "</pastes>").Descendants("paste"))
     {
         yield return(Paste.FromXML(paste));
     }
 }