I want to enumerate all object properties using reflection but i want to exclude the properties that reference objects (this should be fast enough because i'm using in a caching solution using Redis/Booksleve).
Currently i have the following but this return all the object properties including instance members:
var propertyNameAndValues = member.GetType().GetProperties().Where(m => m.GetGetMethod() != null).ToDictionary(i => i.Name, i => Encoding.UTF8.GetBytes(i.GetGetMethod().Invoke(member, null).ToString()));
var task = conn.Hashes.Set(db, string.Format("members:{0}", member.id), propertyNameAndValues);
Use the overload of
GetProperties
where you can specify aBindingFlags
argument and ensureBindingFlags.Static
is included butBindingFlags.Instance
is excluded.For example: