TypeHelper.GetElementType
От: Димчанский Литва http://dimchansky.github.io/
Дата: 28.07.11 19:01
Оценка: 74 (1)
Просматривал исходники. Не пропущен ли return методе TypeHelper.GetElementType?
        public static Type GetElementType(Type type)
        {
            if (type == null)
                return null;

            if (type == typeof(object))
                return type.HasElementType ? type.GetElementType(): null;

            if (type.IsArray)
                /* return ??? */ type.GetElementType();

            if (type.IsGenericType)
                foreach (var aType in type.GetGenericArguments())
                    if (typeof(IEnumerable<>).MakeGenericType(new[] { aType }).IsAssignableFrom(type))
                        return aType;

            var interfaces = type.GetInterfaces();

            if (interfaces != null && interfaces.Length > 0)
            {
                foreach (var iType in interfaces)
                {
                    var eType = GetElementType(iType);

                    if (eType != null)
                        return eType;
                }
            }

            return GetElementType(type.BaseType);
        }
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.