本文整理汇总了C#中System.Xml.Linq.XElement.ElementAsInt方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.ElementAsInt方法的具体用法?C# XElement.ElementAsInt怎么用?C# XElement.ElementAsInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.ElementAsInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Parse episode xml element and returns null if xml is not valid
/// </summary>
/// <param name="episodeXml">Episode xml element</param>
/// <returns>Return parsed episode or null if xml is not valid</returns>
public TheTvDbEpisode Parse(XElement episodeXml)
{
if (episodeXml == null) throw new ArgumentNullException(nameof(episodeXml));
// If episode has no id or number skip parsing and return null
var id = episodeXml.ElementAsUInt("id");
if (!id.HasValue) throw new TheTvDbParseException("Error while parsing an episode xml element. Id is missing.");
var number = episodeXml.ElementAsInt("EpisodeNumber");
if (!number.HasValue) throw new TheTvDbParseException("Error while parsing an episode xml element. EpisodeNumber is missing.");
return new TheTvDbEpisode(id.Value)
{
SeasonId = episodeXml.ElementAsUInt("seasonid"),
SeasonNumber = episodeXml.ElementAsUInt("SeasonNumber"),
EpisodeNumber = number.Value,
EpisodeName = episodeXml.ElementAsString("EpisodeName"),
SeriesId = episodeXml.ElementAsUInt("seriesId"),
FirstAired = episodeXml.ElementAsDateTime("FirstAired"),
Directors = episodeXml.ElementAsString("Director").SplitByPipe(),
GuestStars = episodeXml.ElementAsString("GuestStars").SplitByPipe(),
Description = episodeXml.ElementAsString("Overview", true),
Rating = episodeXml.ElementAsDouble("Rating"),
Writers = episodeXml.ElementAsString("Writer").SplitByPipe(),
RatingCount = episodeXml.ElementAsInt("RatingCount"),
ThumbWidth = episodeXml.ElementAsInt("thumb_width"),
ThumbHeight = episodeXml.ElementAsInt("thumb_height"),
ThumbRemotePath = episodeXml.ElementAsString("filename"),
Language = episodeXml.ElementAsString("Language").ToTheTvDbLanguage(),
LastUpdated = episodeXml.ElementFromEpochToDateTime("lastupdated")
};
}
示例2: Parse
internal override void Parse(XElement element)
{
// Search results have different pagination fields for some reason...
if (element.Name == "search")
{
Start = element.ElementAsInt("results-start");
End = element.ElementAsInt("results-end");
TotalItems = element.ElementAsInt("total-results");
return;
}
var startAttribute = element.Attribute("start");
var endAttribute = element.Attribute("end");
var totalAttribute = element.Attribute("total");
if (startAttribute != null &&
endAttribute != null &&
totalAttribute != null)
{
int start = 0, end = 0, total = 0;
int.TryParse(startAttribute.Value, out start);
int.TryParse(endAttribute.Value, out end);
int.TryParse(totalAttribute.Value, out total);
Start = start;
End = end;
TotalItems = total;
}
}
示例3: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
Status = element.ElementAsString("status");
UpdatedAt = element.ElementAsDateTime("updated_at");
RatingsCount = element.ElementAsInt("ratings_count");
CommentsCount = element.ElementAsInt("comments_count");
}
示例4: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
Title = element.ElementAsString("title");
var authorElement = element.Element("author");
if (authorElement != null)
{
AuthorId = authorElement.ElementAsInt("id");
AuthorName = authorElement.ElementAsString("name");
}
ImageUrl = element.ElementAsString("image_url");
}
示例5: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
Body = element.ElementAsString("body");
var userElement = element.Element("user");
if (userElement != null)
{
User = new UserSummary();
User.Parse(userElement);
}
CreatedAt = element.ElementAsDateTime("created_at");
UpdatedAt = element.ElementAsDateTime("updated_at");
}
示例6: Parse
/// <summary>
/// Parse an actor xml element and returns null if xml not valid
/// </summary>
/// <param name="actorXml">Actor xml element</param>
/// <returns>Returns parsed actor or null if xml is not valid</returns>
public TheTvDbActor Parse(XElement actorXml)
{
if (actorXml == null) throw new ArgumentNullException(nameof(actorXml));
// If actor has no id throw ParseException
var id = actorXml.ElementAsUInt("id");
if (!id.HasValue) throw new TheTvDbParseException("Error while parsing an actor xml element. EpisodeId is missing.");
return new TheTvDbActor(id.Value)
{
ImageRemotePath = actorXml.ElementAsString("Image"),
Name = actorXml.ElementAsString("Name"),
Role = actorXml.ElementAsString("Role"),
SortOrder = actorXml.ElementAsInt("SortOrder").GetValueOrDefault()
};
}
示例7: Parse
/// <summary>
/// Parse banner xml element and returns null if xml is not valid
/// </summary>
/// <param name="bannerXml">Banner xml element</param>
/// <returns>Return the created banner or null if xml is not valid</returns>
public TheTvDbBanner Parse(XElement bannerXml)
{
if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));
TheTvDbBanner banner;
// If banner has no id return null
var id = bannerXml.ElementAsUInt("id");
if (!id.HasValue) throw new TheTvDbParseException("Error while parsing a banner xml element. Banner id is missing.");
var bannerType = bannerXml.ElementAsString("BannerType");
switch (bannerType)
{
case "fanart":
banner = CreateFanart(bannerXml, id.Value);
break;
case "poster":
banner = CreatePoster(bannerXml, id.Value);
break;
case "season":
banner = CreateSeason(bannerXml, id.Value);
break;
case "series":
banner = CreateSeries(bannerXml, id.Value);
break;
default:
throw new TheTvDbParseException(
$"Error while parsing a banner xml element. BannerType '{bannerType}' is unknown.");
}
banner.Language = bannerXml.ElementAsString("Language").ToTheTvDbLanguage();
banner.Rating = bannerXml.ElementAsDouble("Rating");
banner.RatingCount = bannerXml.ElementAsInt("RatingCount");
banner.RemotePath = bannerXml.ElementAsString("BannerPath");
return banner;
}
示例8: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
Name = element.ElementAsString("name");
BookCount = element.ElementAsInt("book_count");
Description = element.ElementAsString("description");
Sort = element.ElementAsString("sort");
IsExclusive = element.ElementAsBool("exclusive_flag");
IsFeatured = element.ElementAsBool("featured");
IsRecommendedFor = element.ElementAsBool("recommended_for");
var orderElement = element.Element("order");
if (orderElement != null)
{
var orderValue = orderElement.Value;
if (!string.IsNullOrWhiteSpace(orderValue))
{
if (orderValue == "a")
{
Order = Response.Order.Ascending;
}
else if (orderValue == "d")
{
Order = Response.Order.Descending;
}
}
}
}
示例9: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
var bookElement = element.Element("book");
if (bookElement != null)
{
Book = new BookSummary();
Book.Parse(bookElement);
}
Rating = element.ElementAsInt("rating");
Votes = element.ElementAsInt("votes");
IsSpoiler = element.ElementAsBool("spoiler_flag");
SpoilersState = element.ElementAsString("spoilers_state");
Shelves = element.ParseChildren<ReviewShelf>("shelves", "shelf");
RecommendedFor = element.ElementAsString("recommended_for");
RecommendedBy = element.ElementAsString("recommended_by");
DateStarted = element.ElementAsDateTime("started_at");
DateRead = element.ElementAsDateTime("read_at");
DateAdded = element.ElementAsDateTime("date_added");
DateUpdated = element.ElementAsDateTime("date_updated");
ReadCount = element.ElementAsInt("read_count");
Body = element.ElementAsString("body");
CommentsCount = element.ElementAsInt("comments_count");
Url = element.ElementAsString("url");
Owned = element.ElementAsInt("owned");
}
示例10: CreateSeason
private static TheTvDbBanner CreateSeason(XElement bannerXml, uint id)
{
if (bannerXml == null) throw new ArgumentNullException(nameof(bannerXml));
return new TheTvDbSeasonBanner(id)
{
Season = bannerXml.ElementAsInt("Season"),
IsWide = bannerXml.ElementAsString("BannerType2") == "seasonwide"
};
}
示例11: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
Name = element.ElementAsString("name");
Role = element.ElementAsString("role");
ImageUrl = element.ElementAsString("image_url");
SmallImageUrl = element.ElementAsString("small_image_url");
Link = element.ElementAsString("link");
AverageRating = element.ElementAsNullableDecimal("average_rating");
RatingsCount = element.ElementAsNullableInt("ratings_count");
TextReviewsCount = element.ElementAsNullableInt("text_reviews_count");
}
示例12: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
Title = element.ElementAsString("title");
Isbn = element.ElementAsString("isbn");
Isbn13 = element.ElementAsString("isbn13");
Asin = element.ElementAsString("asin");
KindleAsin = element.ElementAsString("kindle_asin");
MarketplaceId = element.ElementAsString("marketplace_id");
CountryCode = element.ElementAsString("country_code");
ImageUrl = element.ElementAsString("image_url");
SmallImageUrl = element.ElementAsString("small_image_url");
PublicationDate = element.ElementAsMultiDateField("publication");
Publisher = element.ElementAsString("publisher");
LanguageCode = element.ElementAsString("language_code");
IsEbook = element.ElementAsBool("is_ebook");
Description = element.ElementAsString("description");
AverageRating = element.ElementAsDecimal("average_rating");
Pages = element.ElementAsInt("num_pages");
Format = element.ElementAsString("format");
EditionInformation = element.ElementAsString("edition_information");
RatingsCount = element.ElementAsInt("ratings_count");
TextReviewsCount = element.ElementAsInt("text_reviews_count");
Url = element.ElementAsString("url");
ReviewsWidget = element.ElementAsString("reviews_widget");
var workElement = element.Element("work");
if (workElement != null)
{
Work = new Work();
Work.Parse(element.Element("work"));
}
Authors = element.ParseChildren<AuthorSummary>("authors", "author");
SimilarBooks = element.ParseChildren<BookSummary>("similar_books", "book");
var bookLinks = element.ParseChildren<BookLink>("book_links", "book_link");
if (bookLinks != null)
{
bookLinks.ForEach(x => x.FixBookLink(Id));
BookLinks = bookLinks;
}
var buyLinks = element.ParseChildren<BookLink>("buy_links", "buy_link");
if (buyLinks != null)
{
buyLinks.ForEach(x => x.FixBookLink(Id));
BuyLinks = buyLinks;
}
var shelves = element.ParseChildren(
"popular_shelves",
"shelf",
(shelfElement) =>
{
var shelfName = shelfElement.Attribute("name").Value;
var shelfCountValue = shelfElement.Attribute("count").Value;
int shelfCount = 0;
int.TryParse(shelfCountValue, out shelfCount);
return new KeyValuePair<string, int>(shelfName, shelfCount);
});
if (shelves != null)
{
PopularShelves = shelves.ToDictionary(x => x.Key, x => x.Value);
}
}
示例13: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
var bestBookElement = element.Element("best_book");
if (bestBookElement != null)
{
BestBook = new BestBook();
BestBook.Parse(bestBookElement);
}
BestBookId = element.ElementAsNullableInt("best_book_id");
BooksCount = element.ElementAsInt("books_count");
ReviewsCount = element.ElementAsInt("reviews_count");
RatingsSum = element.ElementAsInt("ratings_sum");
RatingsCount = element.ElementAsInt("ratings_count");
TextReviewsCount = element.ElementAsInt("text_reviews_count");
// Merge the Goodreads publication fields into one date property
var originalPublicationYear = element.ElementAsInt("original_publication_year");
var originalPublicationMonth = element.ElementAsInt("original_publication_month");
var originalPublicationDay = element.ElementAsInt("original_publication_day");
if (originalPublicationYear != 0 && originalPublicationMonth != 0 && originalPublicationDay != 0)
{
OriginalPublicationDate = new DateTime(originalPublicationYear, originalPublicationMonth, originalPublicationDay);
}
OriginalTitle = element.ElementAsString("original_title");
OriginalLanguageId = element.ElementAsNullableInt("original_language_id");
MediaType = element.ElementAsString("media_type");
// Parse out the rating distribution
var ratingDistributionElement = element.ElementAsString("rating_dist");
if (ratingDistributionElement != null)
{
var parts = ratingDistributionElement.Split('|');
if (parts != null && parts.Length > 0)
{
var ratingDistribution = new Dictionary<int, int>();
var ratings = parts.Select(x => x.Split(':'))
.Where(x => x[0] != "total")
.OrderBy(x => x[0]);
foreach (var rating in ratings)
{
int star = 0, count = 0;
int.TryParse(rating[0], out star);
int.TryParse(rating[1], out count);
ratingDistribution.Add(star, count);
}
RatingDistribution = ratingDistribution;
}
}
}
示例14: Parse
internal override void Parse(XElement element)
{
Id = element.ElementAsInt("id");
Name = element.ElementAsString("name");
Link = element.ElementAsString("link");
ImageUrl = element.ElementAsString("image_url");
SmallImageUrl = element.ElementAsString("small_image_url");
FriendsCount = element.ElementAsInt("friends_count");
ReviewsCount = element.ElementAsInt("reviews_count");
CreatedAt = element.ElementAsDateTime("created_at");
}
示例15: Parse
/// <summary>
/// Parse series metadata as xml element and returns null if xml is not valid (series has no id)
/// </summary>
/// <param name="seriesXml">Series metadata as xml element</param>
/// <param name="isSearchElement"></param>
/// <returns>Returns the successfully parsed series</returns>
public TheTvDbSeries Parse(XElement seriesXml, bool isSearchElement = false)
{
if (seriesXml == null) throw new ArgumentNullException(nameof(seriesXml));
// If series has no id throw ParseException
var id = seriesXml.ElementAsUInt("id");
if (!id.HasValue) throw new TheTvDbParseException("Error while parsing a series xml element. Id is missing.");
var series = new TheTvDbSeries(id.Value)
{
ImdbId = seriesXml.ElementAsString("IMDB_ID"),
SeriesName = seriesXml.ElementAsString("SeriesName", true),
Language = seriesXml.ElementAsString(isSearchElement ? "language" : "Language").ToTheTvDbLanguage(),
Network = seriesXml.ElementAsString("Network"),
Description = seriesXml.ElementAsString("Overview", true),
Rating = seriesXml.ElementAsDouble("Rating"),
RatingCount = seriesXml.ElementAsInt("RatingCount"),
Runtime = seriesXml.ElementAsInt("Runtime"),
BannerRemotePath = seriesXml.ElementAsString("banner"),
FanartRemotePath = seriesXml.ElementAsString("fanart"),
LastUpdated = seriesXml.ElementFromEpochToDateTime("lastupdated"),
PosterRemotePath = seriesXml.ElementAsString("poster"),
Zap2ItId = seriesXml.ElementAsString("zap2it_id"),
FirstAired = seriesXml.ElementAsDateTime("FirstAired"),
AirTime = seriesXml.ElementAsTimeSpan("Airs_Time"),
AirDay = seriesXml.ElementAsEnum<TheTvDbFrequency>("Airs_DayOfWeek"),
Status = seriesXml.ElementAsEnum<TheTvDbStatus>("Status"),
ContentRating = seriesXml.ElementAsString("ContentRating").ToTheTvDbContentRating(),
Genres = seriesXml.ElementAsString("Genre").SplitByPipe()
};
if (series.FirstAired.HasValue)
{
series.SeriesName = series.SeriesName.Replace(string.Format(" ({0})", series.FirstAired.Value.Year), "");
}
return series;
}