/// <summary> /// Returns the selected event, if it exists in this type. /// </summary> /// <param name="FindType">Function that returns the selected type from all known types in the assembly.</param> /// <param name="localName">Name of event, local to this type.</param> public DotNetEvent FindInheritedEvent(Func <DotNetQualifiedName, DotNetType> FindType, string localName) { DotNetEvent _event = Events.FirstOrDefault(e => e.Name.LocalName == localName); if (_event != null) { return(_event); } if (BaseType != null) { DotNetType baseType = FindType(BaseType.Name); if (baseType != null) { return(baseType.FindInheritedEvent(FindType, localName)); } } return(null); }
/// <summary> /// For all "inheritdoc" comments, replace the inheritance comment with the inherited comments. /// </summary> /// <remarks> /// Classes can inherit from their base class (or the base class's base, etc). /// Interfaces can inherit from interfaces. /// Class members can inherit from their base class or from interfaces. /// </remarks> /// <param name="FindType">Function that returns the selected type from all known types in the assembly.</param> /// <param name="inheritancePath">List of types or members inheriting from each other, from top level to bottom level. Used to avoid loops.</param> public void ResolveInheritedComments(Func <DotNetQualifiedName, DotNetType> FindType, List <DotNetQualifiedName> inheritancePath = null) { if (inheritancePath == null) { inheritancePath = new List <DotNetQualifiedName>(); } if (inheritancePath.Contains(this.Name)) { return; //inheritance loop } DotNetType baseType = null; if (BaseType != null) { baseType = FindType(BaseType.Name); if (baseType != null && baseType.InheritsDocumentation) { List <DotNetQualifiedName> copiedInheritancePath = inheritancePath.Select(x => x).ToList(); copiedInheritancePath.Add(this.Name); baseType.ResolveInheritedComments(FindType, copiedInheritancePath); } } List <DotNetType> baseInterfaces = new List <DotNetType>(); foreach (DotNetBaseType implementedInterface in ImplementedInterfaces) { DotNetType baseInterface = FindType(implementedInterface.Name); if (baseInterface != null) { baseInterfaces.Add(baseInterface); if (baseInterface.InheritsDocumentation) { List <DotNetQualifiedName> copiedInheritancePath = inheritancePath.Select(x => x).ToList(); copiedInheritancePath.Add(this.Name); baseInterface.ResolveInheritedComments(FindType, copiedInheritancePath); } } } if (this.InheritsDocumentation && baseType != null) { this.CopyComments(baseType); } if (baseType != null) { foreach (DotNetField field in Fields) { if (!field.InheritsDocumentation) { continue; } DotNetField baseField = baseType.FindInheritedField(FindType, field.Name.LocalName); if (baseField != null) { field.CopyComments(baseField); } } } foreach (DotNetProperty property in Properties) { if (!property.InheritsDocumentation) { continue; } if (baseType != null) { DotNetProperty baseProperty = baseType.FindInheritedProperty(FindType, property.Name.LocalName); if (baseProperty != null) { property.CopyComments(baseProperty); continue; } } foreach (DotNetType baseInterface in baseInterfaces) { if (property.Name.ExplicitInterface != null && property.Name.ExplicitInterface != baseInterface.Name) { continue; } DotNetProperty baseProperty = baseInterface.FindInheritedProperty(FindType, property.Name.LocalName); if (baseProperty != null) { property.CopyComments(baseProperty); break; } } } foreach (DotNetEvent _event in Events) { if (!_event.InheritsDocumentation) { continue; } if (baseType != null) { DotNetEvent baseEvent = baseType.FindInheritedEvent(FindType, _event.Name.LocalName); if (baseEvent != null) { _event.CopyComments(baseEvent); continue; } } } foreach (DotNetMethod method in Methods) { if (!method.InheritsDocumentation) { continue; } if (baseType != null) { DotNetMethod baseMethod = baseType.FindInheritedMethod(FindType, method.MethodName); if (baseMethod != null) { method.CopyComments(baseMethod); continue; } } foreach (DotNetType baseInterface in baseInterfaces) { if (method.Name.ExplicitInterface != null && method.Name.ExplicitInterface != baseInterface.Name) { continue; } DotNetMethod baseMethod = baseInterface.FindInheritedMethod(FindType, method.MethodName); if (baseMethod != null) { method.CopyComments(baseMethod); break; } } } foreach (DotNetType nestedType in NestedTypes) { nestedType.ResolveInheritedComments(FindType); } }