Cinchoo – ChoObject.ToString(), Part 1

Cinchoo framework provides one of the very useful method to automatic generation of string represent of an object in very well formatted way.

1. Add reference to Cinchoo.Core.dll assembly

2. Namespace Cinchoo.Core

There are two ways, you can declare the type

Method 1:

Declare a type with public members, use ChoObject.ToString() method to get the string represents as below

public class Security
{
    public string Symbol;
    public string CompanyName;
    public double Price;

    public Security(string symbol, string companyName, double price)
    {
        Symbol = symbol;
        CompanyName = companyName;
        Price = price;
    }
}
static void Main(string[] args)
{
    try
    {
        Security security = new Security("AAPL", "Apple Inc", 457.25);
        Console.WriteLine(ChoObject.ToString(security));
    }
    finally
    {
        ChoAppDomain.Exit();
    }
}

The output is

-- Cinchoo.Core.Test.Security Dump --
        Symbol: AAPL
        CompanyName: Apple Inc
        Price: 457.25

Press any key to continue . . .

Method 2:

Declare a type derived from ChoObject with public members, use ToString() instance method directly to get the string represents as below

public class Security : ChoObject
{
    public string Symbol;
    public string CompanyName;
    public double Price;

    public Security(string symbol, string companyName, double price)
    {
        Symbol = symbol;
        CompanyName = companyName;
        Price = price;
    }
}
static void Main(string[] args)
{
    try
    {
        Security security = new Security("AAPL", "Apple Inc", 457.25);
        Console.WriteLine(security.ToString());
    }
    finally
    {
        ChoAppDomain.Exit();
    }
}

The output is

-- Cinchoo.Core.Test.Security Dump --
        Symbol: AAPL
        CompanyName: Apple Inc
        Price: 457.25

Press any key to continue . . .

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