Aspect that, when applied on a location (field or property), intercepts invocations of
the Get (OnGetValue(LocationInterceptionArgs)) and Set (OnSetValue(LocationInterceptionArgs)) semantics.
Inheritance
Implements
Namespace: PostSharp.Aspects
Assembly: PostSharp.dll
Syntax
[MulticastAttributeUsage(MulticastTargets.Field|MulticastTargets.Property, TargetMemberAttributes = MulticastAttributes.NonAbstract|MulticastAttributes.NonLiteral, AllowExternalAssemblies = false, AllowMultiple = true)]
[HasInheritedAttribute]
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Interface, AllowMultiple = true)]
[AspectConfigurationAttributeType(typeof(LocationInterceptionAspectConfigurationAttribute))]
[Serializer(null)]
public abstract class LocationInterceptionAspect : LocationLevelAspect, ILocationLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ILocationInterceptionAspect, IOnInstanceLocationInitializedAspect, ILocationLevelAspect, IAspectRemarks
<p>
This aspect can be applied indifferently to fields and properties, called <i>locations</i>
because they both have the semantics of a slot where a value can be stored and retrieved.
</p>
<h5>Applying the Aspect on Properties</h5>
<p>Applying an aspect of type <xref href="PostSharp.Aspects.LocationInterceptionAspect" data-throw-if-not-resolved="false"></xref> to a property results in the accessors of this property to be replaced by a call to the method <xref href="PostSharp.Aspects.LocationInterceptionAspect.OnGetValue(PostSharp.Aspects.LocationInterceptionArgs)" data-throw-if-not-resolved="false"></xref>
or <xref href="PostSharp.Aspects.LocationInterceptionAspect.OnSetValue(PostSharp.Aspects.LocationInterceptionArgs)" data-throw-if-not-resolved="false"></xref> of the current class. The original body of the accessor is moved into a new method,
which can be called by the aspect by invoking one of the methods
<xref href="PostSharp.Aspects.LocationInterceptionArgs.ProceedGetValue" data-throw-if-not-resolved="false"></xref>, <xref href="PostSharp.Aspects.LocationInterceptionArgs.ProceedSetValue" data-throw-if-not-resolved="false"></xref>,
<xref href="PostSharp.Aspects.LocationInterceptionArgs.GetCurrentValue" data-throw-if-not-resolved="false"></xref> or <xref href="PostSharp.Aspects.LocationInterceptionArgs.SetNewValue(System.Object)" data-throw-if-not-resolved="false"></xref>,
or by using the <xref href="PostSharp.Aspects.LocationInterceptionArgs.Binding" data-throw-if-not-resolved="false"></xref> object.</p>
<h5>Applying the Aspect on Fields</h5>
<p>Applying this aspect on a field transforms the field into a property of the same name,
scope and visibility as the original field. The original field is removed. Aspect code can get or set the
value of the field by calling the methods <xref href="PostSharp.Aspects.LocationInterceptionArgs.ProceedGetValue" data-throw-if-not-resolved="false"></xref>,
<xref href="PostSharp.Aspects.LocationInterceptionArgs.ProceedSetValue" data-throw-if-not-resolved="false"></xref>, <xref href="PostSharp.Aspects.LocationInterceptionArgs.GetCurrentValue" data-throw-if-not-resolved="false"></xref>
or <xref href="PostSharp.Aspects.LocationInterceptionArgs.SetNewValue(System.Object)" data-throw-if-not-resolved="false"></xref>, or by using the <xref href="PostSharp.Aspects.LocationInterceptionArgs.Binding" data-throw-if-not-resolved="false"></xref> object.</p>
<p><div class="NOTE"><h5>note</h5><p>
Remember to use
<xref href="System.Reflection.PropertyInfo" data-throw-if-not-resolved="false"></xref> instead of <xref href="System.Reflection.FieldInfo" data-throw-if-not-resolved="false"></xref> at runtime to reflect the original field.
For this reason, you cannot store a <xref href="System.Reflection.FieldInfo" data-throw-if-not-resolved="false"></xref> in the aspect.
Store a <xref href="PostSharp.Reflection.LocationInfo" data-throw-if-not-resolved="false"></xref>
instead; even if a <xref href="PostSharp.Reflection.LocationInfo" data-throw-if-not-resolved="false"></xref> represents a field at build time, it will represent
the corresponding <xref href="System.Reflection.PropertyInfo" data-throw-if-not-resolved="false"></xref> at runtime.</p></div></p>
<p><div class="NOTE"><h5>note</h5><p>
When you apply an aspect derived from <xref href="PostSharp.Aspects.LocationInterceptionAspect" data-throw-if-not-resolved="false"></xref> to a value-type field,
you should not pass the value of this field by reference (as an argument to <code>out</code> and <code>ref</code> parameters in C#).
Indeed, PostSharp is unable to detect read and write accesses through references.
</p></div></p>
<p>
note
All classes implementing IAspect should typically be marked as serializable using the SerializableAttribute or PSerializableAttribute custom attribute . Fields that are only used at runtime (and unknown at compile-time) should be carefully marked with the NonSerializedAttribute or PNonSerializedAttribute custom attribute. When PostSharp is used on a platform that does not support aspect serialization (such as .NET Compact Framework, Silverlight, or Windows Phone), or when another aspect serializer is used, it is not necessary to mark the aspect class as serializable. For more information, see Understanding Aspect Serialization .
Constructors
| Name | Description |
|---|---|
| LocationInterceptionAspect() |
Methods
| Name | Description |
|---|---|
| CreateAspectConfiguration() | Method invoked at build time to create a concrete AspectConfiguration instance specifically for the current Aspect type. |
| OnGetValue(LocationInterceptionArgs) | Method invoked instead of the |
| OnInstanceLocationInitialized(LocationInitializationArgs) | Method invoked after an initial value is set for a field or property to which the current aspect is applied. The method is invoked only for instance fields and instance auto-implemented properties, and it is invoked after their inline initialization. For static fields and properties, and for accesses from the constructor, OnSetValue is invoked instead. |
| OnSetValue(LocationInterceptionArgs) | Method invoked instead of the |