public CollectionInformation(Type type) { Type collectionType = EnumerableCollection.BaseCollectionType(type); directFields = collectionType.GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); List <string> foundNames = new List <string> (directFields.Length); foreach (FieldInfo targetField in directFields) { string lastName = targetField.Name; if (targetField.FieldType.Name == "T") { foundNames.Add(lastName); } else if (typeof(EnumerableCollection).IsAssignableFrom(targetField.FieldType)) { CollectionInformation information = EnumerableCollection.GetReflectionInformation(targetField.FieldType); foreach (FieldInfo childInfo in information.directFields) { if (childInfo.FieldType.Name == "T") { foundNames.Add(lastName + "/" + childInfo.Name); } } } } fieldNames = foundNames.ToArray(); }
protected int IndexOf(string fieldName) { CollectionInformation information = ReflectionInformation(); for (int i = 0; i < information.fieldNames.Length; i++) { if (information.fieldNames[i] == fieldName) { return(i); } } Debug.LogError("\"" + fieldName + "\" is not a member of " + GetType().Name + "."); return(-1); }
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); }