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.
$ dotnet add package VersaTul.Display.AttributesThe 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.
To use VersaTul Display Attributes, first install it using nuget:
Install-Package VersaTul.DisplayAttributes
To use VersaTul Display Attributes, you need to import the namespace:
using VersaTul.DisplayAttributes;
Then, you can apply the DisplayAttribute to the properties of your collection data type. For example:
public class Product
{
[Display(Name = "Product ID")]
public int Id { get; set; }
[Display(Name = "Product Name")]
public string Name { get; set; }
[Display(Decimal = 2)]
public decimal Price { get; set; }
[Display(DateFormattingString = "D")]
public DateTime DateAdded { get; set; }
}
The DisplayAttribute provides meta-data to the export engine for outputting data to files. You can specify the following parameters:
Name: The name of the property to be displayed on the file.Decimal: The number of decimal places to round the property value on the file.DateFormattingString: The formatting string for the property value on the file, using the standard date and time format specifiers.You can also use the IFormatter interface to create your own custom formatters for the property values. For example:
public class CurrencyFormatter : IFormatter
{
public object FormatValue(object value)
{
return string.Format("{0:C}", value);
}
}
public class Product
{
// ...
[Display(Formatter = typeof(CurrencyFormatter))]
public decimal Price { get; set; }
// ...
}
The IDisplayAnalyzer interface specifies the functionality provided by a display analyzer. You can use the DisplayAnalyzer class to access the display attributes of a given property. For example:
var analyzer = new DisplayAnalyzer();
var attribute = analyzer.GetAttribute(typeof(Product).GetProperty("Price"));
var name = analyzer.GetName(typeof(Product).GetProperty("Price"));
var value = analyzer.FormatValue(typeof(Product).GetProperty("Price"), 19.99m);
This project is licensed under the MIT License - see the LICENSE file for details.