-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dump of extension methods to the test
- Loading branch information
1 parent
b5a5aa7
commit 9dd12b5
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Samples/Common/Presenters/DumpExtensionMethodsPresenter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.Compilation; | ||
using DotVVM.Framework.Hosting; | ||
using DotVVM.Framework.Utils; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Newtonsoft.Json; | ||
|
||
namespace DotVVM.Samples.Common.Presenters | ||
{ | ||
public class DumpExtensionMethodsPresenter : IDotvvmPresenter | ||
{ | ||
public async Task ProcessRequest(IDotvvmRequestContext context) | ||
{ | ||
var cache = context.Configuration.ServiceProvider.GetService<ExtensionMethodsCache>(); | ||
|
||
var contents = typeof(ExtensionMethodsCache) | ||
.GetField("methodsCache", BindingFlags.Instance | BindingFlags.NonPublic)! | ||
.GetValue(cache) as ConcurrentDictionary<string, ImmutableArray<MethodInfo>>; | ||
|
||
var dump = contents.SelectMany(p => p.Value.Select(m => new { | ||
Namespace = p.Key, | ||
m.Name, | ||
m.DeclaringType!.FullName, | ||
Params = m.GetParameters().Select(p => new { | ||
p.Name, | ||
Type = p.ParameterType!.FullName | ||
}), | ||
m.IsGenericMethodDefinition, | ||
GenericParameters = m.IsGenericMethodDefinition ? m.GetGenericArguments().Select(a => new { | ||
a.Name | ||
}) : null | ||
})) | ||
.OrderBy(m => m.Namespace).ThenBy(m => m.Name); | ||
|
||
await context.HttpContext.Response.WriteAsync("ExtensionMethodsCache dump: " + JsonConvert.SerializeObject(dump)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters