I am trying to make a method that will go through a list of generic objects and replace all their properties of type string which is either null or
I agree with other answers, but I prefer to refactor the search itself to be easly queried with Linq, so the query could be as follow:
var asm = Assembly.GetExecutingAssembly();
var properties = (from prop
in asm.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
where
prop.PropertyType == typeof (string) &&
prop.CanWrite &&
prop.CanRead
select prop).ToList();
properties.ForEach(p => Debug.WriteLine(p.Name));
I took for my example the Assembly type, which hasn't read/write string properties, but if the same code search for just read properties, the result will be:
Which are the string read-only Assembly type properties