forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageInstrumentationServiceAdapter.cs
More file actions
104 lines (91 loc) · 3.83 KB
/
Copy pathPageInstrumentationServiceAdapter.cs
File metadata and controls
104 lines (91 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace System.Web.WebPages.Instrumentation
{
internal partial class PageInstrumentationServiceAdapter
{
private static readonly Type _targetType = typeof(HttpContext).Assembly.GetType("System.Web.Instrumentation.PageInstrumentationService");
private IReadOnlyList<PageExecutionListenerAdapter> _listenerAdapters;
internal PageInstrumentationServiceAdapter()
{
Adaptee = _CallSite_ctor_2.Site();
}
internal PageInstrumentationServiceAdapter(object existing)
{
Adaptee = existing;
}
internal IReadOnlyList<PageExecutionListenerAdapter> ExecutionListeners
{
get
{
if (_listenerAdapters == null)
{
IEnumerable<dynamic> inner = Adaptee.ExecutionListeners;
// Bug 235916: If we pass the type as an object, the callsite is limited to wherever the object is assigned to
// dynamic which avoids private reflection issues in partial trust.
_listenerAdapters = inner.Select(listener => new PageExecutionListenerAdapter((object)listener)).ToList();
}
return _listenerAdapters;
}
}
internal static bool IsEnabled
{
get { return _CallSite_IsEnabled_1.Getter(); }
set { _CallSite_IsEnabled_1.Setter(value); }
}
internal dynamic Adaptee { get; private set; }
private static class _CallSite_IsEnabled_1
{
public static Func<bool> Getter;
public static Action<bool> Setter;
[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Fields cannot be initialized at declaration")]
static _CallSite_IsEnabled_1()
{
PropertyInfo prop = null;
if (_targetType != null)
{
prop = _targetType.GetProperty("IsEnabled", BindingFlags.Static | BindingFlags.Public, Type.DefaultBinder, typeof(bool), Type.EmptyTypes, new ParameterModifier[0]);
}
if (prop != null)
{
Getter = Expression.Lambda<Func<bool>>(Expression.Property(null, prop)).Compile();
ParameterExpression value = Expression.Parameter(typeof(bool));
Setter = Expression.Lambda<Action<bool>>(
Expression.Assign(Expression.Property(null, prop), value), value).Compile();
}
else
{
Getter = () => false;
Setter = _ =>
{
};
}
}
}
private static class _CallSite_ctor_2
{
public static Func<object> Site;
[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Fields cannot be initialized at declaration")]
static _CallSite_ctor_2()
{
if (_targetType != null)
{
Site = Expression.Lambda<Func<object>>(
Expression.New(
_targetType.GetConstructor(new Type[] { })))
.Compile();
}
else
{
Site = () => null;
}
}
}
// END Adaptor Infrastructure Code
}
}