Ejemplo n.º 1
0
 /// <summary>
 /// Adds the type to this namespace
 /// </summary>
 /// <param name="type">The member.</param>
 public void AddType(NType type)
 {
     type.Namespace = this;
     Types.Add(type);
 }
Ejemplo n.º 2
0
        private NClass ProcessInheritance(NType type)
        {
            NClass baseModel = null;
            if (type.Bases.Count > 0)
            {
                var directParent = type.Bases[0];
                baseModel = (NClass)this.FindType(directParent.Id);
            }
            
            if (type.AllMembers.Count > 0)
                return baseModel;

            type.AllMembers.AddRange(type.Members);

            if (baseModel != null)
            {
                this.ProcessInheritance(baseModel);

                var newMembers = new List<INMemberReference>();
                foreach (var nMemberReference in baseModel.AllMembers)
                {
                    // Don't add constructor as inherited member
                    if (nMemberReference is NConstructor)
                        continue;
                    
                    bool addInheritedMember = true;

                    foreach (var currentMember in type.AllMembers)
                    {
                        var method = currentMember as NMethod;

                        // Don't add method that are overriden
                        if (method != null && method.Overrides != null && nMemberReference is NMethod)
                        {
                            if (method.Overrides.Id == nMemberReference.Id)
                            {
                                addInheritedMember = false;
                                break;
                            }
                        }
                    }

                    if (addInheritedMember)
                    {
                        if (nMemberReference is NMethod)
                            type.HasMethods = true;
                        else if (nMemberReference is NProperty)
                            type.HasProperties = true;
                        else if (nMemberReference is NEvent)
                            type.HasEvents = true;

                        newMembers.Add(nMemberReference);
                    }
                }

                type.AllMembers.AddRange(newMembers);
            }

            // Order elements
            type.AllMembers.Sort((from, to) => string.CompareOrdinal(@from.Name, to.Name));

            // Recalculate a PageId based on the number of overriding methods.
            var counters = new Dictionary<string, int>();
            var overrides = new Dictionary<string, int>();
            foreach (var member in type.AllMembers.OfType<NMethod>())
            {
                string id = PageIdFunction(member);

                // Count overrides
                if (!overrides.ContainsKey(member.Name))
                {
                    overrides.Add(member.Name, 0);
                }
                else
                {
                    overrides[member.Name]++;
                }

                // Change only Id that are overlapping
                if (!counters.ContainsKey(id))
                    counters.Add(id, 0);
                else
                {
                    counters[id]++;
                    id = id + "_" + counters[id];
                }

                member.PageId = id;
            }

            // Tag methods that are overriden
            foreach (var method in type.AllMembers.OfType<NMethod>())
            {
                if (overrides.ContainsKey(method.Name) && overrides[method.Name] > 0)
                    method.HasOverrides = true;
            }

            foreach (var nsubClass in type.Members.OfType<NType>())
            {
                ProcessInheritance(nsubClass);
            }

            return baseModel;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Flattens the hierarchy for a class.
        /// </summary>
        /// <param name="baseType">Type of the base.</param>
        /// <param name="currentType">Type of the current.</param>
        private void FlattenHierarchy(NType baseType, NType currentType)
        {
            // Sort the descendants in alphabetical order
            currentType.Descendants.Sort(CompareByDisplayName);

            // Iterate on all descendants
            foreach (var descendantRef in currentType.Descendants)
            {
                var descendant = Registry.FindById(descendantRef.Id) as NType;

                if (descendant != null)
                {
                    int level = 0;
                    int index = 0;
                    for (int i = 0; i < baseType.FlattenedHierarchy.Count; i++)
                    {
                        var flattenItem = baseType.FlattenedHierarchy[i];
                        if (flattenItem.Item2.Id == descendant.Bases[0].Id)
                        {
                            level = flattenItem.Item1;
                            index = i;
                            break;
                        }
                    }

                    // Insert the descendant at the right position in the flattened view
                    baseType.FlattenedHierarchy.Insert(index + 1, new Tuple<int, INMemberReference>(level + 1, descendant));

                    // Flatten the hierarchy for the descendant
                    // note: recursive call here!
                    FlattenHierarchy(baseType, descendant);
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds the type to this namespace
 /// </summary>
 /// <param name="type">The member.</param>
 public void AddType(NType type)
 {
     type.Namespace = this;
     Types.Add(type);
 }