title: Conditions inside Select clause in Linq
body: <p>I have a method that gets a list of objects and then returns all their properties values based on the attributes and types of the property.<br>
   I'm having difficulties with selecting the value because the <strong>Select</strong> depends on conditions.<br>
   What I did so far allows me to get the value in the ugliest way I have ever seen:</p>
  
  <pre><code>public IEnumerable&lt;string&gt; GetValues(List&lt;ProperyInfo&gt; objects)
  {
       var allValues = new List&lt;string&gt;();
       foreach (var obj in objects)
       {
           // Get the PropertyInfo for the obj
           var properties = GetPropertiesWithTheAttributes(obj);
           var values = properties.Select(x =&gt; new 
               {
               Value = x.GetValue(obj, null) == null
                           ?  string.empty
                           :
                           x.PropertyType.BaseType == typeof(Enum)
                           ? Convert.ToInt32(x.GetValue(obj, null)).ToString()
                           : (x.GetValue(obj, null)).ToString(),
               ((ReportAttribute)
               Attribute.GetCustomAttribute(x, typeof(ReportAttribute), false)).Order
               })
               .OrderBy(x =&gt; x.Order)
               .Select(x =&gt; x.Value.ToString())
               .ToList();
  
               allValues.AddRange(values);
      }
  
      return allValues;
  }
  </code></pre>
  
  <p>And in the code I published here I even removed the check for the DisplayDate property in the ReportAttribute, which verifies if the datetime property of the attribute would be displayed as date or datetime...  </p>
  
  <p><strong>serenity now!</strong></p>