Skip to content

Commit d55ca6a

Browse files
committed
Added DisableInstrumentation helper
1 parent e4f9cd2 commit d55ca6a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Griddly.Mvc/GriddlyExtensions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reflection;
45
using System.Web;
56
using System.Web.Mvc;
67
using System.Web.Mvc.Html;
78
using System.Web.Routing;
9+
using System.Web.WebPages;
10+
using System.Web.WebPages.Instrumentation;
811

912
namespace Griddly.Mvc
1013
{
@@ -117,7 +120,7 @@ public static void SetGriddlyDefault<T>(this Controller controller, ref T[] para
117120
}
118121

119122
public static void SetGriddlyDefault<T>(this Controller controller, ref T?[] parameter, string field, IEnumerable<T> value)
120-
where T: struct
123+
where T : struct
121124
{
122125
if (controller.ControllerContext.IsChildAction)
123126
parameter = value.Cast<T?>().ToArray();
@@ -184,5 +187,13 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
184187

185188
return helper.RouteUrl(values);
186189
}
190+
191+
static readonly PropertyInfo _instrumentationService = typeof(WebPageExecutingBase).GetProperty("InstrumentationService", BindingFlags.NonPublic | BindingFlags.Instance);
192+
static readonly PropertyInfo _isAvailableProperty = typeof(InstrumentationService).GetProperty("IsAvailable");
193+
194+
public static void DisableInstrumentation(this WebPageExecutingBase page)
195+
{
196+
_isAvailableProperty.SetValue(_instrumentationService.GetValue(page), false);
197+
}
187198
}
188199
}

0 commit comments

Comments
 (0)