Cinchoo – ChoObject.ToString(), Part 4

Handling Array Members

Cinchoo framework handles Array/List<T> 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 string[] Securities;

    public Portfolio(string name, string description, string[] securities)
    {
        Name = name;
        Description = description;
        Securities = securities;
    }
}
static void Main(string[] args)
{
    try
    {
        Portfolio portfolio = new Portfolio("High-Growth", "High Growth Portfolio", new string[] { "AAPL", "GOOG", "IBM" });
        Console.WriteLine(portfolio.ToString());
    }
    finally
    {
        ChoAppDomain.Exit();
    }
}

The output will be

-- 'High-Growth' Portfolio State --
        Name: High-Growth
        Description: High Growth Portfolio
        Securities [Length: 3]:
                AAPL
                GOOG
                IBM

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