这个可以改吗...
var movies = rawMovies.Movies.Select(m => {
var movie = new Movie {
Id = m.Id,
Title = m.Title,
Year = m.Year,
MpaaRating = m.MpaaRating,
Runtime = m.Runtime,
CriticsConsensus = m.CriticsConsensus,
Synopsis = m.Synopsis,
ReleaseDate = m.ReleaseDates != null ? new ReleaseDate { Dvd = m.ReleaseDates.Dvd, Theater = m.ReleaseDates.Theater } : null,
Rating = m.Ratings != null ? new Rating { AudienceScore = m.Ratings.AudienceScore, CriticsScore = m.Ratings.CriticsScore } : null,
AlternateId = m.AlternateIds != null ? new AlternateId { Imdb = m.AlternateIds.Imdb } : null,
Poster = m.Posters != null ? new Poster { Detailed = m.Posters.Detailed, Original = m.Posters.Original, Profile = m.Posters.Profile, Thumbnail = m.Posters.Thumbnail } : null,
Link = m.Links != null ? new Link { Alternate = m.Links.Alternate, Cast = m.Links.Cast, Clips = m.Links.Clips, Reviews = m.Links.Reviews, Self = m.Links.Self, Similar = m.Links.Similar } : null,
Genres = m.Genres != null ? (HashSet<Genre>)m.Genres.Select(g => new Genre { Name = g }) : new HashSet<Genre>()
};
foreach (var castMember in m.AbridgedCast) {
var person = new Person { Id = castMember.Id, Name = castMember.Name };
if (castMember.Characters != null) {
foreach (string name in castMember.Characters) {
var character = new Character { Name = name, Person = person, Movie = movie };
movie.Characters.Add(character);
}
}
}
return movie;
});
return movies;
foreach(var rawMovie in rawMovies.Movies) { ... }
与yield return
?_