I wanna have all properties of an object which have primitive type, and if the object has a relation to another class , I wanna have the primitive properties of this another
I would made as follows:
void Traverse(Type type, ISet marks, ICollection result)
{
if (marks.Contains(type)) return; else marks.Add(type);
foreach (var propertyInfo in type.GetProperties())
if (propertyInfo.PropertyType.IsPrimitive) result.Add(propertyInfo);
else Traverse(propertyInfo.PropertyType, marks, result);
}
and
var props = new List();
Traverse(yourRootType, new HashSet(), props);