Cinchoo – ChoObject.ToString(), Part 5

Handling of nested types

Cinchoo framework handles nested custom members while constructing string represent of a type.

For a type below having array member

[ChoTypeFormatter("'{this.Name}' Portfolio State")]
public class Portfolio : ChoObject
{
    public string Name;
    public string Description;
    public Security Security;

    public Portfolio(string name, string description, Security security)
    {
        Name = name;
        Description = description;
        Security = security;
    }
}
static void Main(string[] args)
{
    try
    {
        Portfolio portfolio = new Portfolio("High-Growth", "High Growth Portfolio", new Security("AAPL", "Apple Inc", 458.25));
        Console.WriteLine(portfolio.ToString());
    }
    finally
    {
        ChoAppDomain.Exit();
    }
}

The output will be

-- 'High-Growth' Portfolio State --
        Name: High-Growth
        Description: High Growth Portfolio
        Security:
                -- 'AAPL' Security State --
                        Symbol: AAPL
                        CompanyName: Apple Inc
                        Price: 458.25
                        x [Length: 3]:
                                AAPL1
                                APPL2
                                APPL3

Press any key to continue . . .

You can override the default behavior by providing your own formatter. I’ll talk about creating one and using it in a type to customize it.

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