Friday, October 1, 2010

Data Access Continued: Crud Parameter Attribute

In my last blog entry, I decided to pursue writing a data access component model. I have further defined some more requirements:

  • Classes of type T will be required to decorate their properties that are going to be considered as parameters within the ICrud<T> data access implementation. 
  • When applying this decorating attribute to a property, you will be required to provide the following values:
    • ParameterDirection: this will denote if the parameter should expect a value back after the CRUD operation was successful.
    • (Optional) ParameterName: the text used by the ICrud<T> implementation if the CRUD operation needs a different name for the value other than what the parameters base name.
That's enough about requirements! Below is the implementation of this definition!:




[AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
public class CrudParameterAttribute:Attribute
{
    public const string NO_PARAMETER_NAME = "NoParameterName";
    /// <summary>
    /// defines what the Crud data access will interpret the property. 
    /// </summary>
    /// <remarks>
    /// regardless of the direction assigned, the read operations will 
    /// attempt to populate the property. Read operations will only 
    /// use parameters passed into the ICrud object via the 
    /// AddParameter method call.
    /// </remarks>
    public enum Direction 
    {
        /// <summary>
        /// Defines that the property will not be updated by the 
        /// ICrud object after a Create, Update, or Delete calls
        /// </summary>
        Input,
        /// <summary>
        /// Defines that the value within the decorated property
        /// can be effectively ignored for the Create, Update, 
        /// or Delete calls, but it will be populated when the
        /// operation is completed.
        /// </summary>
        Output,
        /// <summary>
        /// Defines that the parameter can be used by the ICrud object
        /// for supplying values, and will be updated after the Create,
        /// Update, or Delete operation is completed.
        /// </summary>
        Both
    }
    /// <summary>
    /// The name that the ICrud operation will used to identify the 
    /// property value uniquely
    /// </summary>
    public string ParameterName { get; private set; }

    /// <summary>
    /// Our way to effect how the ICrud implementation will 
    /// interpret this property
    /// </summary>
    public Direction ParameterDirection { get; private set; }

    /// <summary>
    /// Defines how this property will be interpreted as a parameter 
    /// within an ICrud implementation
    /// </summary>
    /// <param name="direction">
    /// If the property will be populated after an Update, Create, 
    /// or Delete
    /// </param>
    public CrudParameterAttribute(Direction direction)
    {
        this.ParameterDirection = direction;
        // denotes that the property name should be used
        this.ParameterName = NO_PARAMETER_NAME; 
    }

    /// <summary>
    /// Defines how this property will be interpreted as a parameter 
    /// within an ICrud implementation
    /// </summary>
    /// <param name="direction">
    /// If the property will be populated after an Update, Create,
    /// or Delete
    /// </param>
    /// <param name="parameterName">
    /// If the ICrud implementation should refer to the parameter 
    /// by another other than the properties existing name.
    /// </param>
    public CrudParameterAttribute(Direction direction, 
                                   string parameterName)
    {
        this.ParameterDirection = direction;
        this.ParameterName = ParameterName;
    }


}

No comments:

Post a Comment