Catel.Fody.CecilExtensions.GetBaseTypes C# (CSharp) Method

GetBaseTypes() public static method

public static GetBaseTypes ( this type, bool includeIfaces ) : IEnumerable
type this
includeIfaces bool
return IEnumerable
        public static IEnumerable<TypeReference> GetBaseTypes(this TypeDefinition type, bool includeIfaces)
        {
            var result = new List<TypeReference>();

            var current = type;

            var mappedFromSuperType = new List<TypeReference>();

            var previousGenericArgsMap = GetGenericArgsMap(type, new Dictionary<string, TypeReference>(), mappedFromSuperType);

            do
            {
                var currentBase = current.BaseType;
                if (currentBase == null)
                {
                    break;
                }

                if (currentBase is GenericInstanceType)
                {
                    previousGenericArgsMap = GetGenericArgsMap(current.BaseType, previousGenericArgsMap, mappedFromSuperType);

                    if (mappedFromSuperType.Any())
                    {
                        currentBase = ((GenericInstanceType)currentBase).ElementType.MakeGenericInstanceType(previousGenericArgsMap.Select(x => x.Value).ToArray());
                        mappedFromSuperType.Clear();
                    }
                }
                else
                {
                    previousGenericArgsMap = new Dictionary<string, TypeReference>();
                }

                result.Add(currentBase);

                current = current.BaseType.Resolve();

                if (includeIfaces)
                {
                    result.AddRange(BuildIFaces(current, previousGenericArgsMap));
                }
            } while (current.BaseType != null);

            return result;
        }