public CollectionInformation(Type type) { var collectionType = EnumerableCollection.BaseCollectionType(type); directFields = collectionType.GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); var foundNames = new List <string>(directFields.Length); foreach (var targetField in directFields) { string lastName = targetField.Name; if (targetField.FieldType.Name == "T") { foundNames.Add(lastName); } else if (typeof(EnumerableCollection).IsAssignableFrom(targetField.FieldType)) { var information = EnumerableCollection.GetReflectionInformation(targetField.FieldType); foreach (var childInfo in information.directFields) { if (childInfo.FieldType.Name == "T") { foundNames.Add(lastName + "/" + childInfo.Name); } } } } fieldNames = foundNames.ToArray(); }
public static CollectionInformation GetReflectionInformation(Type type) { Type collectionType = EnumerableCollection.BaseCollectionType(type); CollectionInformation information; bool result = ReflectionCache.TryGetValue(collectionType, out information); if (!result) { information = new CollectionInformation(collectionType); ReflectionCache.Add(collectionType, information); } return(information); }