发表敏锐的课程参考问题 [英] Post sharp class reference issue

查看:71
本文介绍了发表敏锐的课程参考问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的类libraray分别有两个类文件,一个类文件有一个post sharp的方面代码如下,

i've class libraray which has two class files separately, one class file has a post sharp's aspect code as follows,

[Serializable]
    
        public class TimingAspect : PostSharp.Aspects.OnMethodBoundaryAspect
        {
            [NonSerialized]
            Stopwatch _StopWatch;

        public override void OnEntry(PostSharp.Aspects.MethodExecutionArgs args)
            {
                _StopWatch = Stopwatch.StartNew();

                base.OnEntry(args);
            }

            public override void OnExit(PostSharp.Aspects.MethodExecutionArgs args)
            {

                StackFrame frame = new StackTrace().GetFrame(1);
                System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\execution time.txt", true);
                file.WriteLine(frame.GetMethod().DeclaringType.FullName + "-------" + frame.GetMethod().Name + "-----" + _StopWatch.ElapsedMilliseconds);
                file.Close();

                base.OnExit(args);
            }
        }





其他类文件的汇编声明如下



other class file has a assembly declaration as follows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
[assembly: AspectLibrary.TimingAspect(AttributeTargetTypes = "Employee.*", AttributeTargetMembers = "Page_Load",AttributePriority=1)]



将该方面添加到我的项目的所有命名空间,我已经将这个类库引用到我的项目中,但属性不适用于我的项目的名称空间



我尝试过:



试图为每个类添加单独的库,如果我在项目中添加该程序集声明类,它可以工作,但我希望它在外面


to add that aspect to all the namespaces of my project, and i've referenced this class library to my project, but attribute won't apply to the name spaces of my projects

What I have tried:

tried to add separate libraries for each class, and if i add that assembly declaration class inside the project ,it works, but i want it to be outside

推荐答案

程序集级属性适用于定义它们的程序集 - 在本例中是PostSharp类库。



他们适用于每个组件都会增加对组件的引用。



您需要将程序集属性声明添加到您希望应用PostSharp方面的每个项目。
Assembly-level attributes apply to the assembly in which they are defined - in this case, your PostSharp class library.

They do NOT apply to every assembly that adds a reference to your assembly.

You need to add the assembly attribute declaration to every project where you want your PostSharp aspect to apply.


这篇关于发表敏锐的课程参考问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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