diff --git a/src/NJsonSchema.Tests/Generation/XmlDocTests.cs b/src/NJsonSchema.Tests/Generation/XmlDocTests.cs
index ec10d8767..d6de7103d 100644
--- a/src/NJsonSchema.Tests/Generation/XmlDocTests.cs
+++ b/src/NJsonSchema.Tests/Generation/XmlDocTests.cs
@@ -118,7 +118,7 @@ public async Task When_xml_doc_is_missing_then_summary_is_missing()
//// Assert
Assert.Empty(summary);
}
-
+
public abstract class BaseBaseClass
{
/// Foo.
diff --git a/src/NJsonSchema/Generation/JsonSchemaGenerator.cs b/src/NJsonSchema/Generation/JsonSchemaGenerator.cs
index ff733f2fb..1947bc34e 100644
--- a/src/NJsonSchema/Generation/JsonSchemaGenerator.cs
+++ b/src/NJsonSchema/Generation/JsonSchemaGenerator.cs
@@ -325,7 +325,7 @@ public virtual string GetPropertyName(Newtonsoft.Json.Serialization.JsonProperty
schema.IsAbstract = type.GetTypeInfo().IsAbstract;
await GeneratePropertiesAndInheritanceAsync(type, schema, schemaResolver).ConfigureAwait(false);
- await ApplyAdditionalPropertiesAsync(type, schema, schemaResolver);
+ await ApplyAdditionalPropertiesAsync(type, schema, schemaResolver).ConfigureAwait(false);
if (Settings.GenerateKnownTypes)
await GenerateKnownTypesAsync(type, schemaResolver).ConfigureAwait(false);
@@ -345,7 +345,7 @@ public virtual string GetPropertyName(Newtonsoft.Json.Serialization.JsonProperty
var genericTypeArguments = extensionDataProperty.PropertyType.GetGenericTypeArguments();
var extensionDataPropertyType = genericTypeArguments.Length == 2 ? genericTypeArguments[1] : typeof(object);
- schema.AdditionalPropertiesSchema = await GenerateWithReferenceAndNullabilityAsync(extensionDataPropertyType, null, schemaResolver);
+ schema.AdditionalPropertiesSchema = await GenerateWithReferenceAndNullabilityAsync(extensionDataPropertyType, null, schemaResolver).ConfigureAwait(false);
}
else
schema.AllowAdditionalProperties = false;
diff --git a/src/NJsonSchema/Infrastructure/DynamicApis.cs b/src/NJsonSchema/Infrastructure/DynamicApis.cs
index 68eb7608b..8743f4a2d 100644
--- a/src/NJsonSchema/Infrastructure/DynamicApis.cs
+++ b/src/NJsonSchema/Infrastructure/DynamicApis.cs
@@ -121,7 +121,7 @@ public static async Task DirectoryExistsAsync(string filePath)
return false;
return await FromResult((bool)DirectoryType.GetRuntimeMethod("Exists",
- new[] { typeof(string) }).Invoke(null, new object[] { filePath }));
+ new[] { typeof(string) }).Invoke(null, new object[] { filePath })).ConfigureAwait(false);
}
/// Checks whether a file exists.
@@ -137,7 +137,7 @@ public static async Task FileExistsAsync(string filePath)
return false;
return await FromResult((bool)FileType.GetRuntimeMethod("Exists",
- new[] { typeof(string) }).Invoke(null, new object[] { filePath }));
+ new[] { typeof(string) }).Invoke(null, new object[] { filePath })).ConfigureAwait(false);
}
/// Reads all content of a file (UTF8).
@@ -206,13 +206,13 @@ public static object XPathEvaluate(XDocument document, string path)
}
#if LEGACY
- private static async Task FromResult(T result)
+ internal static async Task FromResult(T result)
{
return result;
}
#else
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static Task FromResult(T result)
+ internal static Task FromResult(T result)
{
return Task.FromResult(result);
}
diff --git a/src/NJsonSchema/Infrastructure/XmlDocumentationExtensions.cs b/src/NJsonSchema/Infrastructure/XmlDocumentationExtensions.cs
index d05b6f47c..4100d4aaa 100644
--- a/src/NJsonSchema/Infrastructure/XmlDocumentationExtensions.cs
+++ b/src/NJsonSchema/Infrastructure/XmlDocumentationExtensions.cs
@@ -23,10 +23,8 @@ namespace NJsonSchema.Infrastructure
/// This class currently works only on the desktop .NET framework.
public static class XmlDocumentationExtensions
{
- private static readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
-
- private static readonly Dictionary Cache =
- new Dictionary(StringComparer.OrdinalIgnoreCase);
+ private static readonly AsyncLock Lock = new AsyncLock();
+ private static readonly Dictionary Cache = new Dictionary(StringComparer.OrdinalIgnoreCase);
#if !LEGACY
@@ -82,91 +80,6 @@ public static async Task GetXmlRemarksAsync(this MemberInfo member)
return await GetXmlDocumentationTagAsync(member, "remarks").ConfigureAwait(false);
}
- /// Returns the contents of an XML documentation tag for the specified member.
- /// The reflected member.
- /// The contents of the "summary" tag for the member.
- public static Task GetXmlDocumentationAsync(this MemberInfo member)
- {
- return GetXmlDocumentationAsync(member, true);
- }
-
- /// Returns the contents of an XML documentation tag for the specified member.
- /// The reflected member.
- /// Name of the tag.
- /// The contents of the "summary" tag for the member.
- public static async Task GetXmlDocumentationTagAsync(this MemberInfo member, string tagName)
- {
- if (DynamicApis.SupportsXPathApis == false || DynamicApis.SupportsFileApis == false || DynamicApis.SupportsPathApis == false)
- return string.Empty;
-
- var assemblyName = member.Module.Assembly.GetName();
- if (await IgnoreAssemblyAsync(assemblyName, true))
- return string.Empty;
-
- var documentationPath = await GetXmlDocumentationPathAsync(member.Module.Assembly).ConfigureAwait(false);
- var element = await GetXmlDocumentationAsync(member, documentationPath).ConfigureAwait(false);
- return RemoveLineBreakWhiteSpaces(GetXmlDocumentationText(element?.Element(tagName)));
- }
-
- /// Returns the contents of the "returns" or "param" XML documentation tag for the specified parameter.
- /// The reflected parameter or return info.
- /// The contents of the "returns" or "param" tag.
- public static async Task GetXmlDocumentationAsync(this ParameterInfo parameter)
- {
- if (DynamicApis.SupportsXPathApis == false || DynamicApis.SupportsFileApis == false || DynamicApis.SupportsPathApis == false)
- return string.Empty;
-
- var assemblyName = parameter.Member.Module.Assembly.GetName();
- if (await IgnoreAssemblyAsync(assemblyName, true))
- return string.Empty;
-
- var documentationPath = await GetXmlDocumentationPathAsync(parameter.Member.Module.Assembly).ConfigureAwait(false);
- var element = await GetXmlDocumentationAsync(parameter, documentationPath).ConfigureAwait(false);
- return RemoveLineBreakWhiteSpaces(GetXmlDocumentationText(element));
- }
-
- /// Returns the contents of the "summary" XML documentation tag for the specified member.
- /// The type.
- /// The path to the XML documentation file.
- /// The contents of the "summary" tag for the member.
- public static Task GetXmlDocumentationAsync(this Type type, string pathToXmlFile)
- {
- return ((MemberInfo)type.GetTypeInfo()).GetXmlDocumentationAsync(pathToXmlFile);
- }
-
- /// Returns the contents of the "summary" XML documentation tag for the specified member.
- /// The reflected member.
- /// The path to the XML documentation file.
- /// The contents of the "summary" tag for the member.
- public static Task GetXmlDocumentationAsync(this MemberInfo member, string pathToXmlFile)
- {
- return GetXmlDocumentationAsync(member, pathToXmlFile, true);
- }
-
- /// Returns the contents of the "returns" or "param" XML documentation tag for the specified parameter.
- /// The reflected parameter or return info.
- /// The path to the XML documentation file.
- /// The contents of the "returns" or "param" tag.
- public static async Task GetXmlDocumentationAsync(this ParameterInfo parameter, string pathToXmlFile)
- {
- try
- {
- if (pathToXmlFile == null || DynamicApis.SupportsXPathApis == false || DynamicApis.SupportsFileApis == false || DynamicApis.SupportsPathApis == false)
- return null;
-
- var assemblyName = parameter.Member.Module.Assembly.GetName();
- var document = await TryGetXmlDocumentAsync(assemblyName, pathToXmlFile, true);
- if (document == null)
- return null;
-
- return await GetXmlDocumentationAsync(parameter, document);
- }
- catch
- {
- return null;
- }
- }
-
/// Gets the description of the given member (based on the DescriptionAttribute, DisplayAttribute or XML Documentation).
/// The member info
/// The attributes.
@@ -269,52 +182,84 @@ public static string GetXmlDocumentationText(this XElement element)
/// Clears the cache.
/// The task.
- public static async Task ClearCacheAsync()
+ public static Task ClearCacheAsync()
{
-#if !LEGACY
- await _lock.WaitAsync();
-#else
- _lock.Wait();
-#endif
-
- try
+ using (Lock.Lock())
{
Cache.Clear();
+ return DynamicApis.FromResult