Export an object’s properties as comma separated values (CSV) using reflection.
public static string GetCsvHeaderString() { return String.Join(",", typeof(MyClass).GetProperties(). Where<PropertyInfo>(x => x.CanRead). Select<PropertyInfo, string> (x => x.Name).ToArray<string>()); } public string ToCsvString() { return String.Join(",", GetType().GetProperties(). Where<PropertyInfo>(x => x.CanRead). Select<PropertyInfo, string> (x => String.Format("{0}", x.GetValue(this, null).ToString())).ToArray<string>()); }