예제 #1
0
        /// <summary>
        /// Call all the registered custom indexer for an object of a specific type. See <see cref="CustomObjectIndexerAttribute"/>.
        /// </summary>
        /// <param name="documentId">Document id.</param>
        /// <param name="obj">Object to index.</param>
        /// <param name="documentIndex">Document where the indexed object was found.</param>
        /// <param name="so">SerializedObject representation of obj.</param>
        /// <param name="multiLevel">If true, calls all the indexer that would fit the type of the object (all assignable type). If false only check for an indexer registered for the exact type of the Object.</param>
        private void CallCustomIndexers(string documentId, int documentIndex, Object obj, SerializedObject so, bool multiLevel = true)
        {
            var objectType = obj.GetType();
            List <CustomIndexerHandler> customIndexers;

            if (!multiLevel)
            {
                if (!CustomIndexers.TryGetValue(objectType, out customIndexers))
                {
                    return;
                }
            }
            else
            {
                customIndexers = new List <CustomIndexerHandler>();
                foreach (var indexerType in CustomIndexers.types)
                {
                    if (indexerType.IsAssignableFrom(objectType))
                    {
                        customIndexers.AddRange(CustomIndexers.GetHandlers(indexerType));
                    }
                }
            }

            var indexerTarget = new CustomObjectIndexerTarget
            {
                id               = documentId,
                documentIndex    = documentIndex,
                target           = obj,
                serializedObject = so,
                targetType       = objectType
            };

            foreach (var customIndexer in customIndexers)
            {
                customIndexer(indexerTarget, this);
            }
        }
예제 #2
0
 /// <summary>
 /// Checks if we have a custom indexer for the specified type.
 /// </summary>
 /// <param name="type">Type to lookup</param>
 /// <param name="multiLevel">Check for subtypes too.</param>
 /// <returns>True if a custom indexer exists, otherwise false is returned.</returns>
 internal bool HasCustomIndexers(Type type, bool multiLevel = true)
 {
     return(CustomIndexers.HasCustomIndexers(type, multiLevel));
 }