Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Each of your parameters is either adding a filter, or an ignored value. We can construct a list of Predicates, each one corresponding to a single parameter.

 public List<newEvent> toWeb(string name, string egk, string 
 typosSumvan, Boolean olaTaSumvanta)
 {
 var predicates = new List<Predicate<DataRow>>();
 if (!olaTaSumvanta) { predicates.Add(row => row.apodektis == name) }
 if (egk != "") { predicates.Add(row => row.egkatastasi == egk) }
 if (typosSumvan != "") { predicates.Add(row => row.eidosSumvan == typosSumvan) }
 using (var db = new CMMSEntity())
 {
 foreach (var a in db.sumvanta)
 {
 if (a.IsValidEntity(predicates))
 {
 listaSumvantwn.Add(readFromTable(a));
 }
 }
 }
}

Using an extension method taken from this answer this answer, we then apply all the filters.

public static Boolean IsValidEntity<T>(this T entity, IEnumerable<Predicate<T>> predicates)
{
 return predicates.All(p => p(entity));
}

Each of your parameters is either adding a filter, or an ignored value. We can construct a list of Predicates, each one corresponding to a single parameter.

 public List<newEvent> toWeb(string name, string egk, string 
 typosSumvan, Boolean olaTaSumvanta)
 {
 var predicates = new List<Predicate<DataRow>>();
 if (!olaTaSumvanta) { predicates.Add(row => row.apodektis == name) }
 if (egk != "") { predicates.Add(row => row.egkatastasi == egk) }
 if (typosSumvan != "") { predicates.Add(row => row.eidosSumvan == typosSumvan) }
 using (var db = new CMMSEntity())
 {
 foreach (var a in db.sumvanta)
 {
 if (a.IsValidEntity(predicates))
 {
 listaSumvantwn.Add(readFromTable(a));
 }
 }
 }
}

Using an extension method taken from this answer, we then apply all the filters.

public static Boolean IsValidEntity<T>(this T entity, IEnumerable<Predicate<T>> predicates)
{
 return predicates.All(p => p(entity));
}

Each of your parameters is either adding a filter, or an ignored value. We can construct a list of Predicates, each one corresponding to a single parameter.

 public List<newEvent> toWeb(string name, string egk, string 
 typosSumvan, Boolean olaTaSumvanta)
 {
 var predicates = new List<Predicate<DataRow>>();
 if (!olaTaSumvanta) { predicates.Add(row => row.apodektis == name) }
 if (egk != "") { predicates.Add(row => row.egkatastasi == egk) }
 if (typosSumvan != "") { predicates.Add(row => row.eidosSumvan == typosSumvan) }
 using (var db = new CMMSEntity())
 {
 foreach (var a in db.sumvanta)
 {
 if (a.IsValidEntity(predicates))
 {
 listaSumvantwn.Add(readFromTable(a));
 }
 }
 }
}

Using an extension method taken from this answer, we then apply all the filters.

public static Boolean IsValidEntity<T>(this T entity, IEnumerable<Predicate<T>> predicates)
{
 return predicates.All(p => p(entity));
}
Source Link
Caleth
  • 1.5k
  • 9
  • 11

Each of your parameters is either adding a filter, or an ignored value. We can construct a list of Predicates, each one corresponding to a single parameter.

 public List<newEvent> toWeb(string name, string egk, string 
 typosSumvan, Boolean olaTaSumvanta)
 {
 var predicates = new List<Predicate<DataRow>>();
 if (!olaTaSumvanta) { predicates.Add(row => row.apodektis == name) }
 if (egk != "") { predicates.Add(row => row.egkatastasi == egk) }
 if (typosSumvan != "") { predicates.Add(row => row.eidosSumvan == typosSumvan) }
 using (var db = new CMMSEntity())
 {
 foreach (var a in db.sumvanta)
 {
 if (a.IsValidEntity(predicates))
 {
 listaSumvantwn.Add(readFromTable(a));
 }
 }
 }
}

Using an extension method taken from this answer, we then apply all the filters.

public static Boolean IsValidEntity<T>(this T entity, IEnumerable<Predicate<T>> predicates)
{
 return predicates.All(p => p(entity));
}
lang-cs

AltStyle によって変換されたページ (->オリジナル) /