我想在navisworks中转换一个模型中的treeview并创建一个datatable。我试着使用foreach,但没有成功。
任何帮助都将不胜感激
发布于 2017-07-09 12:28:02
我通过获取Descendants并将其传递到IEnumerable中解决了我的问题
var Descendants = PL.oDoc.Models.First.RootItem.Descendants.Select(x => x);然后使用此方法将其转换为datatable:
public static DataTable DataTable<T>(this IEnumerable<T> items)
{
var tb = new DataTable(typeof(T).Name);
PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var prop in props)
{
tb.Columns.Add(prop.Name, prop.PropertyType);
}
foreach (var item in items)
{
var values = new object[props.Length];
for (var i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
tb.Rows.Add(values);
}
return tb;
}https://stackoverflow.com/questions/44905918
复制相似问题