我正在使用Castle DynamicProxy为我的类型添加一个拦截器.现在我需要获得底层基本类型(而不是代理本身).
我在SO上找到了一些提示,建议使用ProxyUtil类,如下所示:
object realInstance = ProxyUtil.GetUnproxiedInstance(proxyInstance);
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用
bool isProxy = ProxyUtil.IsProxy(realInstance);
Run Code Online (Sandbox Code Playgroud)
总是如此.
我还尝试使用以下代码片段,这基本上是ProxyUtil正在做的事情:
var accessor = proxyInstance as IProxyTargetAccessor;
var realInstance = accessor.DynProxyGetTarget();
Run Code Online (Sandbox Code Playgroud)
同样的结果,realInstance仍然是一个代理.
我在这里错过了什么?
我正在使用Telerik的RadControls来实现WPF的隐式样式.以下样式定义如下Themes/Windows8/Telerik.Windows.Controls.RibbonView.xaml:
<Style TargetType="telerikRibbonView:RadRibbonView" x:Key="RadRibbonViewStyle">
...
</Style>
Run Code Online (Sandbox Code Playgroud)
我自己的样式和Telerik默认样式Lib.Windows.Controls在文件夹中的程序集中合并如下Themes:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Windows8/Telerik.Windows.Controls.RibbonView.xaml" />
<ResourceDictionary Source="MyTheme/TelerikCustomizations.xaml" />
<ResourceDictionary>
<!-- avoid optimization -->
<Style TargetType="{x:Type Rectangle}" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
在TelerikCustomizations.xaml我定义以下(空,用于测试目的)样式:
<Style x:Key="MyThemeRadRibbonViewStyle" TargetType="{x:Type telerik:RadRibbonView}" BasedOn="{StaticResource ResourceKey=RadRibbonViewStyle}" />
Run Code Online (Sandbox Code Playgroud)
这会在运行时导致以下异常:
'Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.' Line number '4' and line position '42'.
{"Cannot find resource named 'RadRibbonViewStyle'. Resource names are case sensitive."}
这导致我在MyView.xaml.cs中的以下调试语句:
public ShellView()
{
var baseStyle = FindResource("RadRibbonViewStyle");
var inherited …Run Code Online (Sandbox Code Playgroud)