静态 Aop 织入框架 BSF.Aop

码农软件 · 软件分类 · .NET开发工具 · 2019-11-08 21:56:56

软件介绍

.Net 免费开源,静态 Aop 织入(直接修改 IL 中间语言)框架,类似 PostSharp (收费); 实现前后 Aop 切面和 INotifyPropertyChanged 注入方式。

描述:

  • 项目结构扩展自 BSF 基础架构,但 dll 方面并不依赖 BSF.dll,可以独立开发使用。

  • 项目代码量少(也就几个类文件),核心功能插件化开发,便于第三方扩展,阅读,调试,一起来完善。

  •  .net Aop 静态织入相关的免费开源项目比较少或暂未听闻,故希望开源这块内容,成为同类型开源项目的起点和借鉴。

示例代码:

1) 前后 Aop 切面示例 (详细参考 BSF.Aop.Test 项目)

public class AroundAopTest
    {
        [MyAroundAop]
        [AttributeInfo(Des = "测试2")]
        public void Method(TempInfo info, out int b,int a=1)
        {
            a = 222;
            b = 3;
            System.Console.WriteLine("Hello world!"+a);
        }
    }
    public static class AroundAopTest2
    {
        [MyAroundAop][AttributeInfo(Des ="测试")]
        public static void Method2(TempInfo info, int a = 1)
        {
            a = 222;
            System.Console.WriteLine("Hello world!" + a);
        }
    }
    public class MyAroundAop : Aop.Attributes.Around.AroundAopAttribute
    {
        public MyAroundAop()
        {
        }
        public override void Before(AroundInfo info)
        {
            var att = info.Method.CustomAttributes.ToList()[0];
            info.Params["a"] = 55;
            System.Console.WriteLine("before" + info.Params["a"]);
        }
        public override void After(AroundInfo info)
        {
            System.Console.WriteLine("after"+ info.Params["a"]);
        }
    }
    public class TempInfo
    {
        public int T1 { get; set; }
    }
    public class AttributeInfo : System.Attribute
    {
        public string Des { get; set; }
    }

2) INotifyPropertyChanged 示例(暂未测试真正使用效果,详细参考 BSF.Aop.Test 项目 )

 [NotifyPropertyChangedAop]

public class User
    {
        public string Name { get; set; }
        public int Age { get; set; }
        [NoAop]
        public int B { get; set; }
    }

by 车江毅

本文地址:https://www.codercto.com/soft/d/18572.html

程式之美-微軟技術面試心得

程式之美-微軟技術面試心得

編程之美小 / 悅知文化 / 2008.06.20 / 490元

書內容分為以下幾個部分: ▓ 遊戲之樂:從遊戲和其他有趣問題出發,化繁為簡,分析總結。 ▓ 數字之魅:程式設計的過程實際上就是和數字及字元打交道的過程。這一部分收集了一些這方面的有趣探討。 ▓ 結構之法:彙集了常見的對字串、鏈表、佇列,以及樹進行操作的題目。 ▓ 數學之趣:列舉了一些不需要寫具體程式的數學問題,鍛煉讀者的抽象思考能力。 ▓ 書中絕大部分題目都提供了詳細......一起来看看 《程式之美-微軟技術面試心得》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具