使用 PostSharp 拦截对 Silverlight 对象的调用?
我正在使用 PostSharp 来拦截对我不拥有的对象的方法调用,但我的方面代码似乎没有被调用。 Silverlight 领域的文档似乎相当宽松,所以我很感激你们能提供的任何帮助:)
我有一个属性,如下所示:
public class LogAttribute : OnMethodInvocationAspect
{
public override void OnInvocation(MethodInvocationEventArgs eventArgs)
{
// Logging code goes here...
}
}
在我的 AssemblyInfo 中,有一个条目如下所示:
[assembly: Log(AttributeTargetAssemblies = "System.Windows", AttributeTargetTypes = "System.Windows.Controls.*")]
所以,我向您提出的问题是..我缺少什么? 匹配属性目标下的方法调用似乎不起作用。
I'm working with PostSharp to intercept method calls to objects I don't own, but my aspect code doesn't appear to be getting called. The documentation seems pretty lax in the Silverlight area, so I'd appreciate any help you guys can offer :)
I have an attribute that looks like:
public class LogAttribute : OnMethodInvocationAspect
{
public override void OnInvocation(MethodInvocationEventArgs eventArgs)
{
// Logging code goes here...
}
}
And an entry in my AssemblyInfo that looks like:
[assembly: Log(AttributeTargetAssemblies = "System.Windows", AttributeTargetTypes = "System.Windows.Controls.*")]
So, my question to you is... what am I missing? Method calls under matching attribute targets don't appear to function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信如果您将 AttributeTargetAssemblies 更改为“PresentationFramework”,它可能会起作用。 (PostSharp 还没有安装得那么好)。
WPF 的程序集是PresentationFramework.dll。 AttributeTargetAssemblies 需要它应该定位的 dll。
I believe if you change AttributeTargetAssemblies to "PresentationFramework", it might work. (Don't have PostSharp down that well yet).
The Assembly for WPF is PresentationFramework.dll. The AttributeTargetAssemblies needs the dll that it should target.
PostSharp 有一个新版本,可以从下载页面链接到“所有下载”进行访问。
PostSharp 1.5
PostSharp 的开发分支包括新功能,例如对 Mono、Compact Framework 或 Silverlight 的支持以及方面继承。 如果您想尝试新功能并通过测试新开发来帮助社区,并且可以接受 API 较差的可靠性和稳定性,请从此分支下载。
该版本目前为 1.5 CTP 3,但支持 Silverlight。
PostSharp has a new version, which is accessed from the Downloads page link to "All Downloads".
PostSharp 1.5
The development branch of PostSharp including new features like support for Mono, Compact Framework or Silverlight, and aspect inheritance. Download from this branch if you want to try new features and help the community by testing new developments, and can accept inferior reliability and stability of APIes.
The version is currently at 1.5 CTP 3 but it has support for Silverlight.
当前版本的 PostSharp 无法做到这一点。
PostSharp 的工作原理是在 CLR 加载之前转换程序集。 现在,为了做到这一点,必须发生两件事:
最新版本 1.5 CTP 3 删除了这两个限制中的第一个< /a>,但真正的问题是第二个。 然而,这是一个强烈要求的功能,所以请密切关注去皮:
运行时/第三方方面的陷阱
作者还概述了如果允许在运行时修改则发生的一些问题:
This is not possible with the present version of PostSharp.
PostSharp works by transforming assemblies prior to being loaded by the CLR. Right now, in order to do that, two things have to happen:
The newest version, 1.5 CTP 3, removes the first of these two limitations, but it is the second that's really the problem. This is, however, a heavily requested feature, so keep your eyes peeled:
Runtime/third-party aspect gotchas
The author also proceeds to outline some of the problems that happen if you allow modification at runtime:
如果您尝试拦截框架内的调用(即,不在您自己的代码中),它将不起作用。 PostSharp 只能替换您自己的程序集中的代码。
如果您尝试拦截您正在拨打的电话,那么看起来它应该可以工作。 您是否在构建输出中看到 PostSharp 正在运行?
If you're trying to intercept calls within the framework (i.e., not in your own code), it won't work. PostSharp can only replace code within your own assembly.
If you're trying to intercept calls you're making, then it looks like it should work. Do you see PostSharp running in the build output?