Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Sep 16, 2022
2 parents 99897b7 + e1ed081 commit 21a2b51
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>../Namotion.Reflection.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>2.0.10</Version>
<Version>2.1.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl>https://raw.githubusercontent.com/RicoSuter/Namotion.Reflection/master/assets/NuGetIcon.png</PackageIconUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
34 changes: 34 additions & 0 deletions src/Namotion.Reflection.Tests/XmlDocsExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,40 @@ public void When_summary_has_generic_tags_then_it_is_converted()
Assert.Equal("This are some tags.", summary);
}

[Fact]
public void When_summary_has_generic_tags_then_it_is_converted_to_html()
{
//// Arrange
XmlDocs.ClearCache();

//// Act
XmlDocsOptions options = new XmlDocsOptions()
{
FormattingMode = XmlDocsFormattingMode.Html
};
var summary = typeof(WithGenericTagsInXmlDoc).GetProperty("Foo").GetXmlDocsSummary(options);

//// Assert
Assert.Equal("This <pre>are</pre> <strong>some</strong> tags.", summary);
}

[Fact]
public void When_summary_has_generic_tags_then_it_is_converted_to_markdown()
{
//// Arrange
XmlDocs.ClearCache();

//// Act
XmlDocsOptions options = new XmlDocsOptions()
{
FormattingMode = XmlDocsFormattingMode.Markdown
};
var summary = typeof(WithGenericTagsInXmlDoc).GetProperty("Foo").GetXmlDocsSummary(options);

//// Assert
Assert.Equal("This `are` **some** tags.", summary);
}

public abstract class BaseBaseClass
{
/// <summary>Foo.</summary>
Expand Down
21 changes: 20 additions & 1 deletion src/Namotion.Reflection/Infrastructure/DynamicApis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static bool DirectoryExists(string directoryPath)
#endif
}

/// <summary>Gets all files of directory.</summary>
/// <summary>Gets all files of directory and its sub-directories.</summary>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">The search pattern.</param>
/// <returns>true or false</returns>
Expand All @@ -157,6 +157,25 @@ public static string[] DirectoryGetAllFiles(string path, string searchPattern)
#endif
}

/// <summary>Gets all files of directory.</summary>
/// <param name="path">The directory path.</param>
/// <param name="searchPattern">The search pattern.</param>
/// <returns>true or false</returns>
/// <exception cref="NotSupportedException">The System.IO.Directory API is not available on this platform.</exception>
public static string[] DirectoryGetFiles(string path, string searchPattern)
{
#if NETSTANDARD1_0
if (!SupportsDirectoryApis)
throw new NotSupportedException("The System.IO.Directory API is not available on this platform.");

return (string[])DirectoryType!.GetRuntimeMethods()
.First(m => m.Name == "GetFiles" && m.GetParameters().Length == 2)
.Invoke(null, new object[] { path, searchPattern });
#else
return Directory.GetFiles(path, searchPattern);
#endif
}

/// <summary>Combines two paths.</summary>
/// <param name="path1">The path1.</param>
/// <param name="path2">The path2.</param>
Expand Down
2 changes: 1 addition & 1 deletion src/Namotion.Reflection/Namotion.Reflection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>../Namotion.Reflection.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>2.0.10</Version>
<Version>2.1.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl>https://raw.githubusercontent.com/RicoSuter/Namotion.Reflection/master/assets/NuGetIcon.png</PackageIconUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
11 changes: 5 additions & 6 deletions src/Namotion.Reflection/Performance/CachingXDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ namespace Namotion.Reflection
/// </summary>
internal sealed class CachingXDocument
{
private static readonly object Lock = new();
private static readonly Dictionary<string, XElement?> ElementByNameCache = new();

private static readonly XName XNameDoc = "doc";
private static readonly XName XNameMembers = "members";
private static readonly XName XNameMember = "member";
private static readonly XName XNameName = "name";

private readonly object _lock = new();
private readonly Dictionary<string, XElement?> _elementByNameCache = new();
private readonly XDocument _document;

internal CachingXDocument(string? pathToXmlFile)
Expand All @@ -27,13 +26,13 @@ internal CachingXDocument(string? pathToXmlFile)

internal XElement? GetXmlDocsElement(string name)
{
lock (Lock)
lock (_lock)
{
if (!ElementByNameCache.TryGetValue(name, out var element))
if (!_elementByNameCache.TryGetValue(name, out var element))
{
element = GetXmlDocsElement(_document, name);

ElementByNameCache[name] = element;
_elementByNameCache[name] = element;
}
return element;
}
Expand Down
69 changes: 69 additions & 0 deletions src/Namotion.Reflection/StringBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Text;

namespace Namotion.Reflection
{
/// <summary>
/// Contains extension for <see cref="StringBuilder"/>.
/// </summary>
internal static class StringBuilderExtensions
{
/// <summary>
/// Allows to append multiple strings to the <see cref="StringBuilder"/> at once.
/// </summary>
/// <remarks>
/// Only strings that are neither <c>null</c> nor <c>string.Empty</c> will be added.
/// </remarks>
/// <param name="stringBuilder">The instance of <see cref="StringBuilder"/>.</param>
/// <param name="values">The values to appends.</param>
/// <returns>The value of <paramref name="stringBuilder"/>.</returns>
public static StringBuilder Append(this StringBuilder stringBuilder, params string?[] values)
{
foreach (string? value in values)
{
if (!string.IsNullOrEmpty(value))
{
stringBuilder.Append(value);
}
}
return stringBuilder;
}

/// <summary>
/// Allows to append multiple strings to the <see cref="StringBuilder"/> at once.
/// </summary>
/// <remarks>
/// Only strings that are neither <c>null</c> nor <c>string.Empty</c> will be added.
/// </remarks>
/// <param name="stringBuilder">The instance of <see cref="StringBuilder"/>.</param>
/// <param name="value1">First value to append.</param>
/// <param name="value2">Second value to append.</param>
/// <param name="value3">Third value to append. (optional)</param>
/// <param name="value4">Fourth value to append. (optional)</param>
/// <param name="value5">Fifth value to append. (optional)</param>
/// <param name="value6">Sixth value to append. (optional)</param>
/// <returns>The value of <paramref name="stringBuilder"/>.</returns>
public static StringBuilder Append(this StringBuilder stringBuilder, string? value1, string? value2, string? value3 = null, string? value4 = null, string? value5 = null, string? value6 = null)
{
// Note: only value3 onwards are optional, as StringBuilder contains Append with one string so at least two must
// be specified to call this method

AppendStringToStringBuilder(stringBuilder, value1);
AppendStringToStringBuilder(stringBuilder, value2);
AppendStringToStringBuilder(stringBuilder, value3);
AppendStringToStringBuilder(stringBuilder, value4);
AppendStringToStringBuilder(stringBuilder, value5);
AppendStringToStringBuilder(stringBuilder, value6);

return stringBuilder;

}

private static void AppendStringToStringBuilder(StringBuilder stringBuilder, string? value)
{
if (!string.IsNullOrEmpty(value))
{
stringBuilder.Append(value);
}
}
}
}
Loading

0 comments on commit 21a2b51

Please sign in to comment.