11 changed files with 106 additions and 46 deletions
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Windows.Documents; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.Xml; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// Provides helper methods to create nicely formatted FlowDocuments from NRefactory XmlDoc.
|
||||
/// </summary>
|
||||
public static class XmlDocFormatter |
||||
{ |
||||
public static FlowDocument CreateTooltip(IType type) |
||||
{ |
||||
var ambience = AmbienceService.GetCurrentAmbience(); |
||||
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType | ConversionFlags.UseFullyQualifiedTypeNames; |
||||
string header; |
||||
if (type is ITypeDefinition) |
||||
header = ambience.ConvertEntity((ITypeDefinition)type); |
||||
else |
||||
header = ambience.ConvertType(type); |
||||
|
||||
ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; |
||||
DocumentationUIBuilder b = new DocumentationUIBuilder(ambience); |
||||
b.AddCodeBlock(header, keepLargeMargin: true); |
||||
|
||||
ITypeDefinition entity = type.GetDefinition(); |
||||
if (entity != null) { |
||||
var documentation = XmlDocumentationElement.Get(entity); |
||||
if (documentation != null) { |
||||
foreach (var child in documentation.Children) { |
||||
b.AddDocumentationElement(child); |
||||
} |
||||
} |
||||
} |
||||
return b.CreateFlowDocument(); |
||||
} |
||||
|
||||
public static FlowDocument CreateTooltip(IEntity entity) |
||||
{ |
||||
var ambience = AmbienceService.GetCurrentAmbience(); |
||||
ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType | ConversionFlags.UseFullyQualifiedTypeNames; |
||||
string header = ambience.ConvertEntity(entity); |
||||
var documentation = XmlDocumentationElement.Get(entity); |
||||
|
||||
ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; |
||||
DocumentationUIBuilder b = new DocumentationUIBuilder(ambience); |
||||
b.AddCodeBlock(header, keepLargeMargin: true); |
||||
if (documentation != null) { |
||||
foreach (var child in documentation.Children) { |
||||
b.AddDocumentationElement(child); |
||||
} |
||||
} |
||||
return b.CreateFlowDocument(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue