Display Attributes

Getting Started

The VersaTul Display Attributes project enables the ability to provide meta-data to the export engine for outputting collections as files. This package works with the Collection Streamers package. Attributes can be applied to the properties of a collection data type in order to manipulate the outputted data.

Installation

To use VersaTul Display Attributes, first install it using nuget:

PM> NuGet\Install-Package VersaTul.Display.Attributes -Version latest

Main Components

  1. IFormatter : Specifies the functionality provided by a Display formatter.

  2. IDisplayAnalyzer : Specifies the functionality provided by a Display analyzer.

  3. DisplayAttribute : Apply to a property in order to provide meta-data to the export engine for outputting data to files.

  4. DateFormatter : Represents the formatter for formatting dates, this uses the standard date and time format specifiers.

  5. DecimalFormatter : Represents the formatter for formatting decimals.

Functional Summary

  1. DisplayAttribute.Display(Name = “New-Display-Name”) : Apply to property to change property name on export.

  2. DisplayAttribute.Display(Decimal = 2) : Apply to floating point properties to round property value on export.

  3. DisplayAttribute.Display(DateFormattingString = “D”) : Apply to DateTime properties to format value on export.

  4. object IDisplayAnalyzer.FormatValue() : Overloaded method for formatting a given property value base on the Display setting.

  5. DisplayAttribute IDisplayAnalyzer.GetAttribute(PropertyInfo propertyInfo) : Gets the DisplayAttribute value added to a given Property.

  6. string IDisplayAnalyzer.GetName(PropertyInfo propertyInfo) : Returns the name of the property wither the name of the current member or the overridden name by the Display Attribute.

Code Examples

Display Attribute Usage
class Order
{
    public int OrderId { get; set; }

    [Display(Name = "Shipping")] //Rename to Shipping
    public string ShipVia { get; set; }

    [Display(Decimals = 2)] //Round value to 2 decimal places
    public decimal SubTotal { get; set; }

    public IEnumerable<OrderItem> Items { get; set; }

    [Display(DateFormattingString = "D")] //Format to Long date pattern.
    public DateTime OrderDate { get; set; }

    public Customer Customer { get; set; }

    public string OrderNumber { get; set; }

    public bool IsMailSent { get; set; }
}

Changelog

V1.0.6

  • Minor fixes

  • Dependent package updates

V1.0.5

  • Minor fixes

  • Dependent package updates

V1.0.4

  • Code ported to dotnet core

  • Documentation completed