不确定我的问题是否有意义,但如果有人遇到类似的情况,我最终会遍历我的对象的属性并截断字符串,然后再在 radgrid 上设置数据源。
public static void SM_Dump_TruncStrings(ref List<myDataType> dump, int maxLength, bool addEllipses)
{
foreach (var sm in dump)
{
PropertyInfo[] infos = sm.GetType().GetProperties();
foreach (var info in infos)
{
if (info.PropertyType == typeof(string))
{
var origValue = info.GetValue(sm, null) as string;
if (origValue != null && origValue.Length > maxLength)
{
var newVal = origValue.Substring(0, maxLength);
if (addEllipses)
newVal += "...";
info.SetValue(sm, newVal, null);
}
}
}
}
}
这种方法取自这里:How to iterate through each property of a custom vb.net object?
干杯,
生锈的