Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }