Cinchoo – ChoObject.ToString(), Part 8

Cinchoo framework works very well with derived classes while generating string represent. Here I’ll walk you over with a sample

[ChoTypeFormatter("'{this.Symbol}' Security State")]
public class Security : ChoObject
{
    public string Symbol;
    public string CompanyName;
    [ChoMemberFormatter("Last Price")]
    public double Price;

    public Security(string symbol, string companyName, double price)
    {
        Symbol = symbol;
        CompanyName = companyName;
        Price = price;
    }
}

[ChoTypeFormatter("'{this.Symbol}' Stock State")]
public class Stock : Security
{
    public string Exchange;

    public Stock(string symbol, string companyName, double price)
        : base(symbol, companyName, price)
    {
    }
}

static void Main(string[] args)
{
    try
    {
        Stock security = new Stock("AAPL", "Apple Inc", 457.25);
        security.Exchange = "NYSE";
        Console.WriteLine(security.ToString());
    }
    finally
    {
        ChoAppDomain.Exit();
    }
}

The output will be

-- 'AAPL' Stock State --
        Exchange: NYSE
        Symbol: AAPL
        CompanyName: Apple Inc
        Last Price: 457.25

Happy coding!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s