C# has a cool feature - yield keyword. Your case looks perfect to use its benefits:
public static IEnumerable<string> GetRelease() { using (WebClient webClient = new WebClient()) { Stream stream = webClient.OpenRead(RemoteReleaseFile); using (StreamReader streamReader = new StreamReader(stream)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { yield return line; } } } } }
Consider using IEnumerable instead of List whenever suitable suitable. Here
public static List<string> PremierPublishers() { using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"])) { return connection.Query<string>("Select PremierPublisher From PremierPublishers").ToList(); } }
C# has a cool feature - yield keyword. Your case looks perfect to use its benefits:
public static IEnumerable<string> GetRelease() { using (WebClient webClient = new WebClient()) { Stream stream = webClient.OpenRead(RemoteReleaseFile); using (StreamReader streamReader = new StreamReader(stream)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { yield return line; } } } } }
Consider using IEnumerable instead of List whenever suitable. Here
public static List<string> PremierPublishers() { using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"])) { return connection.Query<string>("Select PremierPublisher From PremierPublishers").ToList(); } }
C# has a cool feature - yield keyword. Your case looks perfect to use its benefits:
public static IEnumerable<string> GetRelease() { using (WebClient webClient = new WebClient()) { Stream stream = webClient.OpenRead(RemoteReleaseFile); using (StreamReader streamReader = new StreamReader(stream)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { yield return line; } } } } }
Consider using IEnumerable instead of List whenever suitable. Here
public static List<string> PremierPublishers() { using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"])) { return connection.Query<string>("Select PremierPublisher From PremierPublishers").ToList(); } }
C# has a cool feature - yield keyword. Your case looks perfect to use its benefits benefits:
public static IEnumerable<string> GetRelease() { using (WebClient webClient = new WebClient()) { Stream stream = webClient.OpenRead(RemoteReleaseFile); using (StreamReader streamReader = new StreamReader(stream)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { yield return line; } } } } }
Consider using IEnumerable instead of List whenever suitable. Here
public static List<string> PremierPublishers() { using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"])) { return connection.Query<string>("Select PremierPublisher From PremierPublishers").ToList(); } }
C# has a cool feature - yield keyword. Your case looks perfect to use its benefits:
public static IEnumerable<string> GetRelease() { using (WebClient webClient = new WebClient()) { Stream stream = webClient.OpenRead(RemoteReleaseFile); using (StreamReader streamReader = new StreamReader(stream)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { yield return line; } } } } }
Consider using IEnumerable instead of List whenever suitable. Here
public static List<string> PremierPublishers() { using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"])) { return connection.Query<string>("Select PremierPublisher From PremierPublishers").ToList(); } }
C# has a cool feature - yield keyword. Your case looks perfect to use its benefits:
public static IEnumerable<string> GetRelease() { using (WebClient webClient = new WebClient()) { Stream stream = webClient.OpenRead(RemoteReleaseFile); using (StreamReader streamReader = new StreamReader(stream)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { yield return line; } } } } }
Consider using IEnumerable instead of List whenever suitable. Here
public static List<string> PremierPublishers() { using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"])) { return connection.Query<string>("Select PremierPublisher From PremierPublishers").ToList(); } }
So, above other answers.
C# has a cool feature - yield keyword. Your case looks perfect to use its benefits:
public static IEnumerable<string> GetRelease() { using (WebClient webClient = new WebClient()) { Stream stream = webClient.OpenRead(RemoteReleaseFile); using (StreamReader streamReader = new StreamReader(stream)) { while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (!string.IsNullOrWhiteSpace(line)) { yield return line; } } } } }
Consider using IEnumerable instead of List whenever suitable. Here
public static List<string> PremierPublishers() { using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"])) { return connection.Query<string>("Select PremierPublisher From PremierPublishers").ToList(); } }
you do not really need a list as you do not use its features (e.g. indexing) later and need it just once in your code. So you can simplify and perhaps accelerate it:
public static IEnumerable<string> PremierPublishers()
{
using (IDbConnection connection = new SqlConnection(ConfigurationManager.AppSettings["Previews"]))
{
return connection.Query<string>("Select PremierPublisher From PremierPublishers");
}
}
After changing the type of premierPublishers in the caller everything remains working.
Actually, this line looks weird to me:
var premierPublishers = Release.PremierPublishers();
PremierPublishers() appears to be a method, thus it should start with a verb in its name, smth like GetPremierPublishers(). Otherwise it looks like a new object instantiation.
Here
if (lineitem.Count() == 3)
3 is a kind of maaagic. Better extract it to a private static readonly int naming it smth like NumberOfPartsInComicsLine. Yes, the name is not the best but this is really what you hope to get here.
I would also do something with the algorithm itself. Look at this logic:
if (line.Contains(NewReleasesFor)) { releaseDate = DateTime.Parse(line.Substring(line.Length - 10)); }
The thing is that effectively this condition will be true just once, when parsing the first line. However, it will be tested for each of the zillion lines you get. So perhaps you should take and handle the first line separately in the beginning and then iterate through all the remaining lines.