Aspectsharp language document

Source: Internet
Author: User
<Doctype HTML public-wcdtd XHTML stricten httpwwwworgtrxhtmldtdxhtml-strictdtd>

The objective of aspect # is to avoid the hassle of rolling over XML syntax. It provides a clean way to configure, identify, and write your configuration.

Content Index

1. Basic Definition
2. Import
3. Global interceptor
4. Global Mixin Mixing
5. aspect
6. Include
7. pointcut
8. Notify advice


1. Basic Definition

When using the aspect # language, you must follow some rules. The first rule is the sequence. Therefore, your statement must follow the following sequence:

[Import]

[Interceptor global interceptor ing]

[Mixin global ing]

Aspects aspect Definition


2. Import

The import area helps you maintain a clean code environment and help aspect explain class declaration.

Import namespace name [in assembly name]

For example:

Import system. collections in System

Import aspectsharp. Core


3. Global interceptor

When you have an interceptor that is ready to apply multiple sections or even multiple entry points, you can define it to the global interceptor area:

Interceptors [
"Key name 1": Interceptor Class;
"Key name 2": Interceptor Class B
]

For example

Interceptors [
"Logger": digitalgravity. interceptors. Logger in digitalgravity. xproject
]

This is a ing declaration without importing the namespace.

Import digitalgravity. interceptors in digitalgravity. xproject

Interceptors [
"Logger": Logger
]

This is the ing Declaration of the imported namespace.

After completing these steps, you can use the keyword advice in a section definition to reference them based on the "key name:

Aspect test for myclass

Pointcut method (*)
Advice ("key ")
End

Pointcut property (*)
Advice ("key2 ")
End

End


4. Global Mixing

For the same reason, we also need a global hybrid zone:

Mixins [
"Key name 1": mixed into Class;
"Key name 2": mixed into Class B
]

For example

Mixins [
"Security": digitalgravity. mixins. securitymixin in digitalgravity. xproject
]

This is a ing declaration without importing the namespace.

Import digitalgravity. mixins in digitalgravity. xproject

Mixins [
"Security": securitymixin
]

This is the ing Declaration of the imported namespace.

After completing these steps, you can use the include keyword in a section definition and reference them based on the "key name:

Aspect test for myclass

Include ("security ")

End

Note that Mixin uses include references while the interceptor uses advice references.


5. aspect

A section defines the Mixin and pointcut entries that will be applied to one or more classes:

Aspect section name for Class Name
[Import]
[Entry point]
End

For example

Aspect myaspect for customer
End

This is an example of declaring a plane for a specific class (customer.

Aspect myaspect for [My. namespace. Classes excludes (customer, author)]
End

This is an example of the class declaration section in a specific namespace (My. namespace. classes), but the customer and author classes are excluded.

Aspect myaspect for [assignablefrom (customer)]
End

This is an example of all class declarations inherited or implemented from the customer parent class or interface.

Aspect myaspect for [custommatcher (custom matcher class name)]
End

This is an example of using a custom checkpoint.

When you call the aspectengine. Wrap () method in an instance, basically aspect # tries to find the matching section of the instance. If multiple slices match, a new slice is created from the set and defined as this slice. (???)

If you need to use more special semantics when matching the aspect, you can use the custommatcher keyword (as shown in the example above) to provide your own aspect matching. Your class must implement the iclassmatcher interface and write the logic so that the instance returns the true value when it meets your desired aspect requirements.


6. Reference include

You can use one or more include references in one aspect definition to introduce the defined Mixin.

Include ("key name ")

This is a reference method after global ing is declared.

Include class name in assembly

This is a reference method that does not declare global ing.

For example

Aspect myaspect for customer
Include digitalgravity. mixins. Security in digitalgravity. xproject
Include system. Collections. arraylist IN SYSTEM
End



7. pointcut

The purpose of the entry point is to define a set of valid expressions for notification execution,

Pointcut [target] [method signature]
Advice (class name)
Advice ("key name ")
End

The target may be method, property, propertyread, or propertywrite.

If needed, you can combine them like this:

Pointcut method | property (*)
End
Pointcut method | propertyread (*)
End
Pointcut propertywrite (*)
End

However, using property | propertywrite is meaningless and you will also get an error.

The "method signature" can be as simple as a (*) representing all, or (system. ilist create (INT, *) indicates that all return types are system. ilist and at least the first parameter type is the int method named create. Note that here, the return value type and parameter type must use the complete class name, just as system. ilist, rather than just ilist.

Regular expressions are not fully supported. In fact, you can only use. * To match the rest of a name, such as (Str. * Create (INT, string) will match all parameters with two types (the first parameter is 'int' and the second parameter is 'string') and return a name prefix 'str' (for example, 'string, strange, stripissimo.

For example

// All read and write attributes named name

Pointcut property (* name)
End
// All read and write attributes like C ***** names, such as mermername

Pointcut property (string C. * name)
End

// Method with the return type void, no parameter, and name of perform

Pointcut method (void perform)
End

// The first parameter is of the string type, and we do not care about the method named perform of other parameters.

Pointcut method (void perform (string ,*))
End



8. Notify advice

The notification advice is a code snippet related to the entry point. Aspect # only supports method blocker notifications.

Advice ("key name ")

Advice (interceptor class name)

Advice (interceptor class name in assembly name)

Please note that we use delayed loading for the interceptor, and each time an interceptor has only one instance. In other words, multiple proxies do not share the interceptor.

For example

Aspect myaspect for customer
Pointcut method (*)
Advice (loginvocationinterceptor)
End
End
Aspect myaspect for customer
Pointcut method (*)
Advice (namespace. mylogger in myassembly)
End
End

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.