using System.Reflection;
public String ParseToCsv(MyModel entity)
{
Type type = entity.GetType();
IList<PropertyInfo> props = new List<PropertyInfo>(type.GetProperties());
foreach (PropertyInfo prop in props){
var propName = prop.Name;
var propValue = prop.GetValue(entity)
as String;
Debug.WriteLine("{0} :
{1}",
propName, propValue);
}
}
public partial class MyModel
{
public string CsvName { get; set; }
public string CsvDate { get; set; }
public string CsvExtension { get; set; }
public string RecordNumber { get; set; }
}
|
沒有留言:
張貼留言