Cinchoo – ChoObject.ToString(), Part 7

Customizing the member names

When constructing automatic string represent of an object, Cinchoo framework uses the member name as a title for each member. You can override this behavior by decorating each member with ChoMemberFormatterAttribute.

[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;

static void Main(string[] args)
        Security security = new Security("AAPL", "Apple Inc", 457.25);

The output will be

-- 'AAPL' Security State --
        Symbol: AAPL
        CompanyName: Apple Inc
        Last Price: 457.25

Happy coding!!!

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s