c# - Is it possible to make use of a list from an object by its object type? -
I am trying to remove items from different lists and items. I have at least classes, in my case I will be given the object name of the list and then I have to delete items from that list. Is it possible to access a specific list only by its object type?
As an example I will be given "TestSubcolleciton" and after that I have to access some subcollecitons list to delete some records.
Private Classes TestClassWithSubcollection: BaseObject {public list & lt; TestSubcolleciton & gt; Subclassions {get; Set; } Public listing & lt; TestSubcollecitonSecond & gt; SubcollecitonSeconds {Receive; Set; }} Protected Class TestSubcolleciton {Secure Ent ID (get; Set;}} Protected Class TestSubcollecitonSecond {Secure Ent ID (get; set;}}
). MakeGenericType (listItemType); .. PropertyInfo property = instance.GetType () GetProperties () FirstOrDefault (P = & gt; p.PropertyType == genericListType); if (property! = Null) Return (IList) property. Return withdrawal;}
This gives blank or empty space for the first part of a list.
Can use:
TestClassWithSubcollection example = ... IList list = GetListByItemType (e.g., TypeSubcollecitonSecond); If (list! = Null) {// ...}
If you need to get it from the">
This is used like this:
IList list = GetListByItemType (e.g., "TestSubcollecitonSecond"); If (list! = Null) {// ...}
Comments
Post a Comment