DynamicApis
Provides dynamic access to framework APIs.
using System;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace NJsonSchema.Infrastructure
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public static class DynamicApis
{
[System.Runtime.CompilerServices.Nullable(2)]
private static readonly Type HttpClientType;
[System.Runtime.CompilerServices.Nullable(2)]
private static readonly Type HttpClientHandlerType;
[System.Runtime.CompilerServices.Nullable(2)]
private static readonly Type DecompressionMethodsType;
public static bool SupportsHttpClientApis {
get {
if (HttpClientType != (Type)null && HttpClientHandlerType != (Type)null)
return DecompressionMethodsType != (Type)null;
return false;
}
}
static DynamicApis()
{
HttpClientType = TryLoadType("System.Net.Http.HttpClient, System.Net.Http", "System.Net.Http.HttpClient, System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
HttpClientHandlerType = TryLoadType("System.Net.Http.HttpClientHandler, System.Net.Http", "System.Net.Http.HttpClientHandler, System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
DecompressionMethodsType = TryLoadType("System.Net.DecompressionMethods, System.Net.Primitives", "System.Net.DecompressionMethods, System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
}
[AsyncStateMachine(typeof(<HttpGetAsync>d__6))]
public static Task<string> HttpGetAsync(string url, CancellationToken cancellationToken)
{
<HttpGetAsync>d__6 stateMachine = default(<HttpGetAsync>d__6);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<string>.Create();
stateMachine.url = url;
stateMachine.cancellationToken = cancellationToken;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
private static int GenerateAllDecompressionMethodsEnumValue()
{
return (from int val in Enum.GetValues(DecompressionMethodsType)
where val > 0
select val).Aggregate(0, (int accumulated, int newValue) => accumulated | newValue);
}
public static string HandleSubdirectoryRelativeReferences(string fullPath, string jsonPath)
{
try {
if (!Directory.Exists(Path.GetDirectoryName(fullPath))) {
string fileName = Path.GetFileName(fullPath);
string directoryName = Path.GetDirectoryName(fullPath);
string path = directoryName.Replace("\\", "/").Split(new char[1] {
'/'
}).Last();
DirectoryInfo parent = Directory.GetParent(directoryName);
if (!string.IsNullOrWhiteSpace(parent?.FullName)) {
string[] directories = Directory.GetDirectories(parent.FullName);
foreach (string path2 in directories) {
string text = Path.Combine(path2, path);
string text2 = Path.Combine(text, fileName);
if (Directory.Exists(text)) {
fullPath = Path.Combine(text, fileName);
break;
}
}
}
}
if (!File.Exists(fullPath)) {
string directoryName2 = Path.GetDirectoryName(fullPath);
if (Directory.Exists(directoryName2)) {
string fileName2 = Path.GetFileName(fullPath);
string[] array = fullPath.Replace("\\", "/").Split(new char[1] {
'/'
});
string text3 = array[array.Length - 2];
string[] directories2 = Directory.GetDirectories(directoryName2);
foreach (string path3 in directories2) {
string path4 = Path.Combine(path3, fileName2);
if (File.Exists(path4) && File.ReadAllText(path4).Contains(jsonPath.Split(new char[1] {
'/'
}).Last())) {
fullPath = Path.Combine(path3, fileName2);
break;
}
}
}
}
return fullPath;
} catch {
return fullPath;
}
}
[return: System.Runtime.CompilerServices.Nullable(2)]
private static Type TryLoadType(params string[] typeNames)
{
foreach (string typeName in typeNames) {
try {
Type type = Type.GetType(typeName, false);
if (type != (Type)null)
return type;
} catch {
}
}
return null;
}
}
}