public IList<CellData> DumpPropertyValues(object data, string parent = "", int dumpLevel = 2)
{
if (data == null) return null;
var propertyGetters = FastReflection.Instance.GetGetterDelegates(data.GetType());
foreach (var propertyGetter in propertyGetters)
{
var dataValue = propertyGetter.GetterFunc(data);
if (dataValue == null)
{
var nullDisplayText = propertyGetter.MemberInfo.GetNullDisplayTextAttribute();
_result.Add(new CellData
{
PropertyName = parent + propertyGetter.Name,
PropertyValue = nullDisplayText,
PropertyIndex = _index++,
PropertyType = propertyGetter.PropertyType
});
}
else if (propertyGetter.PropertyType.IsEnum)
{
var enumValue = ((Enum)dataValue).GetEnumStringValue();
_result.Add(new CellData
{
PropertyName = parent + propertyGetter.Name,
PropertyValue = enumValue,
PropertyIndex = _index++,
PropertyType = propertyGetter.PropertyType
});
}
else if (isNestedProperty(propertyGetter.PropertyType))
{
_result.Add(new CellData
{
PropertyName = parent + propertyGetter.Name,
PropertyValue = dataValue,
PropertyIndex = _index++,
PropertyType = propertyGetter.PropertyType
});
if (parent.Split('.').Length > dumpLevel)
{
continue;
}
DumpPropertyValues(dataValue, parent + propertyGetter.Name + ".", dumpLevel);
}
else
{
_result.Add(new CellData
{
PropertyName = parent + propertyGetter.Name,
PropertyValue = dataValue,
PropertyIndex = _index++,
PropertyType = propertyGetter.PropertyType
});
}
}
return _result;
}