Initializes a new instance of the FormatAttribute class.

Namespace: Dapfor.Net.Formats
Assembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)

Syntax

C#
public FormatAttribute(
	Type formatType
)
Visual Basic
Public Sub New ( 
	formatType As Type
)
Visual C++
public:
FormatAttribute(
	Type^ formatType
)
F#
new : 
        formatType : Type -> FormatAttribute

Parameters

formatType
Type: System..::..Type
Type of the format.

Examples

 Copy imageCopy
//Some data object
public class File
{
    private long size;

    [Format(typeof(SizeCustomFormat))]
    public long Size
    {
        get { return size; }
        set { size = value; }
    }
}

//Custom format
public class SizeCustomFormat : IFormat
{
    public string Format(IDataField dataField)
    {
        decimal value = Convert.ToDecimal(dataField.Value);
        value = Decimal.Ceiling(value/1024);

        return value != 0 ? string.Format("{0:n0} Ko", value) : string.Empty;
    }

    public bool CanParse(string text, IDataField dataField)
    {
        return false;
    }

    public void Parse(string text, IDataField dataField)
    {
    }

    public object Clone()
    {
        return new SizeCustomFormat();
    }
}

See Also