PostSharp-如何将方法注入类? [英] PostSharp - How to inject a method into a class?

查看:52
本文介绍了PostSharp-如何将方法注入类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PostSharp遇到了一些问题(我认为该问题可以由其他库解决)。
我有这种情况:

I have some problem with PostSharp (I assume that problem can be solved by other library). I have that scenario:

我必须获取名称包含单词(例如 Sth)的所有类。我的项目中有这些类(示例):

I must get all classes with name containing a word, e.g "Sth". I have that classes in my project (an example):

SthClass1.cs
SthClassBlabla.cs
SthClass3.cs

我发现使用 PostSharp

[assembly: TraceAttribute( AttributeTargetMembers = "Sth*")]

然后,是否可以为每个找到的类注入(使用Aspect,PostSharp(?))代码?

then, is it possible to inject (using aspect, PostSharp (?)) code for each found class ?

示例:

 SthClass1 myObj = new SthClass1();
 myObj.ClassMethod1();
 myObj.ClassMethod2();
 myObj.InjectedMethod(); //that method belongs to the aspect


推荐答案

是的,您使用介绍。

http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-14-e28093-Introducing-members-and-interfaces-Part-1。 aspx

http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-15-e28093-Introducing-members-and-interfaces -Part-2.aspx

这篇关于PostSharp-如何将方法注入类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆