IdeaBlade DevForce 2010 Help Reference
BeforeGetAttribute Class
Members  Example  See Also  Send Feedback
IdeaBlade.Core Assembly > IdeaBlade.Core Namespace : BeforeGetAttribute Class



Marks an action to be performed in a property getter before the value is retrieved from the backing store.

Syntax

Visual Basic (Declaration) 
<AttributeUsageAttribute(ValidOn=AttributeTargets.Method, 
   AllowMultiple=True, 
   Inherited=True)>
Public Class BeforeGetAttribute 
   Inherits PropertyInterceptorAttribute
   Implements System.Runtime.InteropServices._Attribute 
Visual Basic (Usage)Copy Code
Dim instance As BeforeGetAttribute
C# 
[AttributeUsageAttribute(ValidOn=AttributeTargets.Method, 
   AllowMultiple=true, 
   Inherited=true)]
public class BeforeGetAttribute : PropertyInterceptorAttribute, System.Runtime.InteropServices._Attribute  
C++/CLI 
[AttributeUsageAttribute(ValidOn=AttributeTargets.Method, 
   AllowMultiple=true, 
   Inherited=true)]
public ref class BeforeGetAttribute : public PropertyInterceptorAttribute, System.Runtime.InteropServices._Attribute  

Example

C#Copy Code
public partial class Customer {

  // Sample signatures for a BeforeGet method for any Customer property
  // (invoked for both simple and navigation properties).
  // Additional signatures are possible.

  // Signature 1 - accept a property value and return a property value.
  // The input value may be null if no prior BeforeGet interceptors 
  // have returned a value.
  // Any value returned is passed to next interceptor.
  [BeforeGet]
  public object BeforeGetAnyCustomerProperty1(object value) {
    Console.WriteLine("Getting a customer property 1");
    return value;
  }

  // Signature 2 - accept a property value, but no return value.
  [BeforeGet]
  public void BeforeGetAnyCustomerProperty2(object value) {
    Console.WriteLine("Getting a customer property 2");
  }

  // Signature 3 - accept base IPropertyInterceptorArgs.
  // Allows you to cancel further actions and modify the Value.
  // No property information available.
  [BeforeGet]
  public void BeforeGetAnyCustomerProperty3(IPropertyInterceptorArgs args) {
    Console.WriteLine("Getting a customer property 3");
  }

  // Signature 4 - accept EntityProperty interceptor arguments.
  // The arguments passed allow you to determine the property retrieved
  // and to cancel the get if necessary.  The args.Value may be null
  // if no prior BeforeGet interceptor has set the value.  args.Value
  // can also be set before returning.
  [BeforeGet]
  public void BeforeGetAnyCustomerProperty4(IEntityPropertyGetInterceptorArgs args) {
    Console.WriteLine("Getting customer property " + args.EntityProperty.Name);
  }

  // Signature 5 - accept strongly-typed IPropertyInterceptorArgs.
  // Same features as IPropertyInterceptorArgs but Instance is now strongly-typed.
  [BeforeGet]
  public void BeforeGetAnyCustomerProperty5(IPropertyInterceptorArgs<Customer, object> args) {
    Customer c = args.Instance;
    Console.WriteLine("Getting customer property 5");
  }
}

Remarks

Use BeforeGet to specify one or more actions to be performed when a property getter is invoked. These actions occur before the backing value is retrieved. Actions may be defined as instance or static methods on a base or derived type. The execution order may be specified by using the Order named parameter. See the Developer's Guide for more information on action chaining and ordering. BeforeGet interceptor actions are automatically discovered the first time a property getter is called.

There are a number of acceptable signatures for methods marked with this attribute. In general, you can accept (or accept and return) an object of the expected property type, or accept one of the many derivations of PropertyInterceptorArgs. See the examples provided with the constructors for more information. If a signature is invalid, you will receive a PropertyInterceptorException when DevForce either builds or tries to execute the method, depending on when the error is detected.

Inheritance Hierarchy

System.Object
   System.Attribute
      IdeaBlade.Core.PropertyInterceptorAttribute
         IdeaBlade.Core.BeforeGetAttribute

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.