KellermanSoftware.CompareNetObjects.TypeComparers.PropertyComparer.IsValidIndexer C# (CSharp) Method

IsValidIndexer() private method

private IsValidIndexer ( ComparisonConfig config, PropertyInfo info, string breadCrumb ) : bool
config ComparisonConfig
info System.Reflection.PropertyInfo
breadCrumb string
return bool
        private bool IsValidIndexer(ComparisonConfig config, PropertyInfo info, string breadCrumb)
        {
            ParameterInfo[] indexers = info.GetIndexParameters();

            if (indexers.Length == 0)
            {
                return false;
            }

            if (config.SkipInvalidIndexers)
                return false;

            if (indexers.Length > 1)
            {
                if (config.SkipInvalidIndexers)
                    return false;

                throw new Exception("Cannot compare objects with more than one indexer for object " + breadCrumb);
            }

            if (indexers[0].ParameterType != typeof(Int32))
            {
                if (config.SkipInvalidIndexers)
                    return false;

                throw new Exception("Cannot compare objects with a non integer indexer for object " + breadCrumb);
            }

#if !NEWPCL
            var type = info.ReflectedType;
#else
            var type = info.DeclaringType;
#endif
            if (type == null)
            {
                if (config.SkipInvalidIndexers)
                    return false;

                throw new Exception("Cannot compare objects with a null indexer for object " + breadCrumb);
            }

            if (type.GetProperty("Count") == null
                || type.GetProperty("Count").PropertyType != typeof(Int32))
            {
                if (config.SkipInvalidIndexers)
                    return false;

                throw new Exception("Indexer must have a corresponding Count property that is an integer for object " + breadCrumb);
            }

            return true;
        }
    }