/// <summary> /// Stores the specified type of information. /// </summary> /// <param name="type">The type information.</param> internal void StoreTypeInfo(TypeWithComment type) { if (type.Info.IsConstructedGenericType) { // m_Types[type.Info.GetGenericTypeDefinition()] = type; m_Types[type.Info] = type; } else { m_Types[type.Info] = type; } if (type.Comment != null && !type.Comment.IsEmpty) { m_TypeComments[type.Comment.Signature] = type; } foreach (var method in type.Methods) { if (method.Comment.IsEmpty) { continue; } m_MethodComments[method.Comment.Signature] = method; } foreach (var prop in type.Properties) { if (prop.Comment.IsEmpty) { continue; } m_PropertyComments[prop.Comment.Signature] = prop; } foreach (var field in type.Fields) { if (field.Comment.IsEmpty) { continue; } m_FieldComments[field.Comment.Signature] = field; } foreach (var evt in type.Events) { if (evt.Comment.IsEmpty) { continue; } m_EventComments[evt.Comment.Signature] = evt; } }
/// <summary> /// Gets the specified type of information. If no XML comment is found, returns empty XML comment information. /// </summary> /// <param name="type">The type.</param> /// <returns>The type information.</returns> public TypeWithComment GetTypeInfo(Type type) { if (TryGetTypeInfo(type, out var info) && info != null) { return(info); } info = new TypeWithComment(type, null, this); StoreTypeInfo(info); return(info); }
/// <summary> /// Loads the types defined in the specified assembly. /// </summary> /// <param name="dllPath">The assembly file path.</param> /// <param name="context">The context that manages the state of the output process for class documents.</param> /// <param name="nameSpace">The namespace to load.</param> /// <returns>The type information.</returns> private static IEnumerable <TypeWithComment> EnumerateTypes(string dllPath, ClassDocContext context, string?nameSpace = null) { var xmlPath = Path.Combine(Directory.GetParent(dllPath).FullName, Path.GetFileNameWithoutExtension(dllPath) + ".xml"); IEnumerable <XmlComment> comments = new XmlComment[0]; if (File.Exists(xmlPath)) { comments = XmlCommentReader.ReadXmlComments(XDocument.Parse(File.ReadAllText(xmlPath)), context, nameSpace); } var commentsLookup = comments.ToLookup(x => x.TypeName); // List<TypeWithComment> typeComments = new List<TypeWithComment>(); Func <Type, bool> typeFilter; if (!string.IsNullOrEmpty(nameSpace)) { typeFilter = type => { if (!type.Namespace.StartsWith(nameSpace)) { return(false); } if (context.TypeFilter != null && !context.TypeFilter(type)) { return(false); } return(true); }; } else { typeFilter = context.TypeFilter; } foreach (var type in EnumerateTypes(Assembly.LoadFrom(dllPath), typeFilter)) { var info = new TypeWithComment(type, commentsLookup, context); // typeComments.Add(info); context.StoreTypeInfo(info); yield return(info); } // return typeComments.AsReadOnly(); }
/// <summary> /// Gets the inherited XML comment. /// </summary> /// <returns></returns> protected override XmlComment?GetInheritComment() { var baseMethod = Info.GetBaseDefinition(); TypeWithComment baseType = Context.GetTypeInfo(baseMethod.DeclaringType); foreach (var m in baseType.Methods) { if (m.Info == baseMethod) { return(m.Comment); } } return(null); }
/// <inheritdoc/> protected override XmlComment?GetInheritComment() { MethodInfo?method = Info.GetAddMethod(true) ?? Info.GetRemoveMethod(true) ?? Info.GetRaiseMethod(true); if (method == null) { return(null); } var baseMethod = method.GetBaseDefinition(); TypeWithComment baseType = Context.GetTypeInfo(baseMethod.DeclaringType); foreach (var e in baseType.Events) { if (e.Name == this.Name) { return(e.Comment); } } return(null); }
/// <summary> /// Gets the inherited XML comment. /// </summary> /// <returns></returns> protected override XmlComment?GetInheritComment() { MethodInfo[] methods = Info.GetAccessors(true); if (methods == null || methods.Length == 0) { return(null); } var baseMethod = methods[0].GetBaseDefinition(); TypeWithComment baseType = Context.GetTypeInfo(baseMethod.DeclaringType); foreach (var m in baseType.Methods) { if (m.Info == baseMethod) { return(m.Comment); } } return(null); }
/// <summary> /// Gets information for the specified type. /// </summary> /// <param name="typeSignature">XML comment signature.</param> /// <param name="type">The type information.</param> /// <returns>Returns true if found. Otherwise, false.</returns> internal bool TryGetTypeInfo(XmlCommentSignature typeSignature, out TypeWithComment type) { return(m_TypeComments.TryGetValue(typeSignature, out type)); }