I am on the receiving end of a class that contains several lists. A stripped down version is something like:
public class DS : FTSAction
{
public IList<FlsGroup> FLS_GROUP;
public IList<FlsMcCity> FLS_MC_CITY;
public IList<FlsMcCounty> FLS_MC_COUNTY;
public IList<FlsCode> FLS_CODE;
public DS();
public int? Id { get; set; }
public string Name { get; set; }
}
I am trying to iterate through the "properties" of the class in order to pull out and do some processing on only the IList objects in the object.
Having stolen some code from elsewhere here in StackOverflow, I have this:
private DS UpdateDataSet = DSClient.GetResult(); //Fills out the object
foreach ( PropertyInfo pi in typeof( DataSynch ).GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ) )
{
var _item_type = Nullable.GetUnderlyingType( pi.PropertyType) ?? pi.PropertyType;
if ( _item_type == typeof( IList<> ) )
{
var l = pi.GetValue( UpdateDataSet, null );
}
}
The trouble is that while I see "Id" and "Name" in the outer loop, which are skipped because they're not IList types, I never see any of the ILists at all. They're simply not part of what I get with the foreach loop. I'm not sure, but I suspect that they're objects in their own right and that's why they're not picked up by the loop, but I don't know.
So the question is - How do I get to the IList items?
Thanks