.net - How to exclude Dictionary properties such as Comparer when getting properties using Reflection TypeDescriptor.GetProperties? -
i have below line of code properties on object validated dictionary object @ run time.
dim properties system.componentmodel.propertydescriptorcollection = _ system.componentmodel.typedescriptor.getproperties(pobject)
but including comparer property in properties result. how can exclude property? know workaround? thank help!
if know properties want exclude (by name) can exclude them explicitly. propertydescriptorcollection
type weird one, ienumerable
, it's not ienumerable<propertydescriptor>
, , additionally, if via getproperties
call it's read-only, cannot remove directly.
can do, create new list, move need there, , then, create propertydescriptorcollection
new list, this:
dim pobject = new dictionary(of string, string) dim properties propertydescriptorcollection = _ typedescriptor.getproperties(pobject) ' create new list dim proplist = new list(of propertydescriptor) ' loop through properties each propertydesc in properties if propertydesc.name <> "comparer" 'add need list proplist.add(propertydesc) end if next 'make new collection properties need properties = new propertydescriptorcollection(proplist.toarray)
Comments
Post a Comment