[Open Source]. Net Aop (static weaving) Framework BSF. Aop, aopbsf. aop

Source: Internet
Author: User

[Open Source]. Net Aop (static weaving) Framework BSF. Aop, aopbsf. aop
BSF. Aop

. NetFree open-source, static Aop weaving(Directly modify the IL intermediate language) framework, similar to PostSharp (charged );
Implements the Aop aspect and INotifyPropertyChanged injection methods.

Open Source Address: https://git.oschina.net/chejiangyi/BSF.Aop

Open source QQ group:. net open source basic service 238543768 welcome

Description:

  • Static weaving implementation delivers almost the same performance as native code writing.
  • The project structure is extended from the BSF infrastructure, but the dll does not depend on BSF. dll and can be developed and used independently.
  • The project has a small amount of code (just a few files), and core functions are developed in Plug-ins to facilitate third-party expansion, reading, debugging, and improvement.
  • . Net Aop has few or not heard of free open-source projects related to static weaving. Therefore, it is hoped that the open-source content will become the starting point and reference of the same type of open-source projects.

 

Use Configuration

1) The project references BSF. Aop. dll, Mono. Cecil. dll, and Mono. Cecil. Pdb. dll.
2) Add AopStartLoader. Start () in the project startup code.
(This code is used for automatic injection scanning, automatic configuration of vs project environment, and export of related exe files)

Note:

  • Add Web project in Application_Start
  • Add Winform project in Pragram. Main
Automatic configuration (recommended by default)

Build the project, and then run the debugging project directly.

Note:

  • AopStartLoader. Start (); the first time the Code is run in the project, an error is reported because the Aop environment has not been set up automatically. After the first run and automatic setup is successful, all the subsequent runs are automatically injected.
  • By default, the "packages. BSF. Aop" folder is generated under the project, and the "aop running script" is injected into the PostBuildEvent event of the vs project. For details, refer to the "manual configuration content" below ".
Manual configuration (recommended for problems)

1) configure the Aop injection directory.
In the vs project, create the packages. BSF. Aop Directory, which contains bsf.aop.ilrun.exe, BSF. Aop. dll, Mono. Cecil. Pdb. dll, and Mono. Cecil. dll files.
2) configure the PostBuildEvent script.

Winform Environment:

Open vs-project properties-PostBuildEvent and configure the aop running script. For example:
Xcopy $ (OutDir) BSF. Aop. dll $ (ProjectDir) packages. BSF. Aop \/Y
Call "$ (ProjectDir) packages. BSF. Aop \ BSF.Aop.ILRun.exe" msgbox $ (TargetDir)

Web Environment:

Open vs-project properties-PostBuildEvent and configure the aop running script. (Replace OpenApi. Test. Web with a specific project name.) For example:
Xcopy $ (SolutionDir) \ OpenApi. Test. Web \ bin \ BSF. Aop. dll $ (SolutionDir) \ OpenApi. Test. Web \ packages. BSF. Aop \/Y
Call "$ (SolutionDir) \ OpenApi. Test. Web \ packages. BSF. Aop \ BSF.Aop.ILRun.exe" msgbox $ (SolutionDir) \ OpenApi. Test. Web \ bin \

Demo

1) Examples of front and back Aop aspect (For more information, see BSF. Aop. Test.)

Public class AroundAopTest {[MyAroundAop] [AttributeInfo (Des = "Test 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 =" test ")] 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 example (the actual use effect is not tested yet,For more information, see BSF. Aop. Test.)

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

 

By che jiangyi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.