, , .
XML, CSV . CSV ( , CSV ).
.
CSV 1 ():
ID,GivenName,FamilyName
1,John,A
2,Mike,B
CSV- 2 ( "" ):
Date,Anniversary
1.1.,New year
CSV " "; , ? ? "" ""? ?
. , CSV . .
, ( ).
: ( , ):
1,John,A
1.1.,New year
2,Mike,B
, ? , " CSV", , . , .
, , ( , , - ). .
:
public abstract class AbstractModel : ObservableObject
{
protected string Prefix(object data)
{
if (ReferenceEquals(data, null))
return string.Empty;
string result = data.ToString();
if (data.Contains(",") || data.Contains("\""))
return $"\"{data}\"";
return data;
}
}
public class RealModel : AbstractModel
{
public string PropertyA {get; set;}
public string PropertyB {get; set;}
public override string ToString()
{
return $"{Prefix(PropertyA)},{Prefix(PropertyB)}";
}
}
:
using (StreamWriter file = new StreamWriter("path"))
{
foreach (AbstractModel instance in allInstances)
file.WriteLine(instance);
}