我有这门课
public class MyViewModel {
public MyClass Thing { get; set; }
public int Id { get { return Thing.Id; } }
public string Name { get { return Thing.Name; } }
}
我注意到当我将它绑定到 ASP.NET GridView 时,它会自动省略Thing
,并且有充分的理由(即,否则它只会在所有行中显示无意义的“MyNamespace.MyClass”)
我正在尝试用这种方法做类似的事情。
public static string ConvertToCsv<T>(IEnumerable<T> items)
{
foreach (T item in items)
{
if(item is not a native/.NET class) // <-- How do you do this?
continue;
else // If it is a string/int/bool/DateTime or something meaningful
{
...
}
}
}