Skip to main content
deleted 9 characters in body
Source Link
Sunny
  • 366
  • 1
  • 5

Using "&&" it will stop the evaluation at the first false, so something like this should work for you:

public class MyClass { public string Item1 { get; set; } public string Item2 { get; set; } public string Item3 { get; set; } public string Long { get; set; } public string Lat { get; set; } public override string ToString() { var sb = new StringBuilder(); var isFullyPopulatedtempVar = (AddPropertyData(sb, "{0}", Item1) && AddPropertyData(sb, ", item2 {0}", Item2) && AddPropertyData(sb, ", item3 {0}", Item3)) && AddPropertyData(sb, ", long: {0}, lat: {1}", Long, Lat); return sb.Length > 0 ? sb.ToString() : Item1; } private static bool AddPropertyData(StringBuilder sb, string format, params string[] data) { if (data.All(x => !String.IsNullOrWhiteSpace(x))) { sb.AppendFormat(format, data); return true; } return false; } } 

Using "&&" it will stop the evaluation at the first false, so something like this should work for you:

public class MyClass { public string Item1 { get; set; } public string Item2 { get; set; } public string Item3 { get; set; } public string Long { get; set; } public string Lat { get; set; } public override string ToString() { var sb = new StringBuilder(); var isFullyPopulated = (AddPropertyData(sb, "{0}", Item1) && AddPropertyData(sb, ", item2 {0}", Item2) && AddPropertyData(sb, ", item3 {0}", Item3)) && AddPropertyData(sb, ", long: {0}, lat: {1}", Long, Lat); return sb.Length > 0 ? sb.ToString() : Item1; } private static bool AddPropertyData(StringBuilder sb, string format, params string[] data) { if (data.All(x => !String.IsNullOrWhiteSpace(x))) { sb.AppendFormat(format, data); return true; } return false; } } 

Using "&&" it will stop the evaluation at the first false, so something like this should work for you:

public class MyClass { public string Item1 { get; set; } public string Item2 { get; set; } public string Item3 { get; set; } public string Long { get; set; } public string Lat { get; set; } public override string ToString() { var sb = new StringBuilder(); var tempVar = (AddPropertyData(sb, "{0}", Item1) && AddPropertyData(sb, ", item2 {0}", Item2) && AddPropertyData(sb, ", item3 {0}", Item3)) && AddPropertyData(sb, ", long: {0}, lat: {1}", Long, Lat); return sb.Length > 0 ? sb.ToString() : Item1; } private static bool AddPropertyData(StringBuilder sb, string format, params string[] data) { if (data.All(x => !String.IsNullOrWhiteSpace(x))) { sb.AppendFormat(format, data); return true; } return false; } } 
as per loki's comment
Source Link
Sunny
  • 366
  • 1
  • 5

Using "&&" it will stop the evaluation at the first false, so something like this should work for you:

public class MyClass { public string Item1 { get; set; } public string Item2 { get; set; } public string Item3 { get; set; } public string Long { get; set; } public string Lat { get; set; } public override string ToString() { var sb = new StringBuilder(); var isFullyPopulated = (AddPropertyData(Item1sb, "{0}", sbItem1) && AddPropertyData(Item2sb, ", item2 {0}", sbItem2) && AddPropertyData(Item3sb, ", item3 {0}", sbItem3)) && AddPropertyData(sb, ", long: {0}, lat: {1}", Long, Lat); return sb.Length > 0 ? sb.ToString() : Item1;   }   private static bool AddPropertyData(stringStringBuilder datasb, string formatStringformat, StringBuilderparams sbstring[] data) { if (!data.All(x string=> !String.IsNullOrWhiteSpace(datax))) { sb.AppendFormat(formatStringformat, data); return true; } return false; } } 

Using "&&" it will stop the evaluation at the first false, so something like this should work for you:

public class MyClass { public string Item1 { get; set; } public string Item2 { get; set; } public string Item3 { get; set; } public override string ToString() { var sb = new StringBuilder(); var isFullyPopulated = (AddPropertyData(Item1, "{0}", sb) && AddPropertyData(Item2, ", item2 {0}", sb) && AddPropertyData(Item3, ", item3 {0}", sb)); return sb.Length > 0 ? sb.ToString() : Item1;   } private bool AddPropertyData(string data, string formatString, StringBuilder sb) { if (! string.IsNullOrWhiteSpace(data)) { sb.AppendFormat(formatString, data); return true; } return false; } } 

Using "&&" it will stop the evaluation at the first false, so something like this should work for you:

public class MyClass { public string Item1 { get; set; } public string Item2 { get; set; } public string Item3 { get; set; } public string Long { get; set; } public string Lat { get; set; } public override string ToString() { var sb = new StringBuilder(); var isFullyPopulated = (AddPropertyData(sb, "{0}", Item1) && AddPropertyData(sb, ", item2 {0}", Item2) && AddPropertyData(sb, ", item3 {0}", Item3)) && AddPropertyData(sb, ", long: {0}, lat: {1}", Long, Lat); return sb.Length > 0 ? sb.ToString() : Item1; }   private static bool AddPropertyData(StringBuilder sb, string format, params string[] data) { if (data.All(x => !String.IsNullOrWhiteSpace(x))) { sb.AppendFormat(format, data); return true; } return false; } } 
Source Link
Sunny
  • 366
  • 1
  • 5

Using "&&" it will stop the evaluation at the first false, so something like this should work for you:

public class MyClass { public string Item1 { get; set; } public string Item2 { get; set; } public string Item3 { get; set; } public override string ToString() { var sb = new StringBuilder(); var isFullyPopulated = (AddPropertyData(Item1, "{0}", sb) && AddPropertyData(Item2, ", item2 {0}", sb) && AddPropertyData(Item3, ", item3 {0}", sb)); return sb.Length > 0 ? sb.ToString() : Item1; } private bool AddPropertyData(string data, string formatString, StringBuilder sb) { if (! string.IsNullOrWhiteSpace(data)) { sb.AppendFormat(formatString, data); return true; } return false; } }