Tag Archives: Cinchoo

Cinchoo – Using Performance Counters, Part 2

This article is the continuation of previous one. So far you learned how to create and use performance counters in your application. In this section, I’ll show you how to control them through configuration.

Cinchoo framework generates meta data configuration file for all the performance counters you created in your application. This file will be created automatically in the application configuration folder. The file name will be [appExeName].perf.meta.

If you application executable name is HelloWorld.exe, this meta data file will be created in the name of HelloWorld.perf.meta. This is the default behavior.

This file name can be overridden. Please visit Framework Configuration Parameters section on how to achieve it.

For the samples from the previous sections, the meta data file will be created as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <PerformanceCounterCategory name="Random Single Instance Test">
    <PerformanceCounter name="Random Rate" turnOn="true" />
    <PerformanceCounter name="Random Average" turnOn="true" />
  </PerformanceCounterCategory>
  <PerformanceCounterCategory name="Random Multiple Instance Test">
    <PerformanceCounter name="Random Value" instanceName="Standard" turnOn="true" />
    <PerformanceCounter name="Random Value" instanceName="Inverted" turnOn="true" />
  </PerformanceCounterCategory>
</configuration>

PerformanceCounterCategory section will be created for corresponding performance counter category. A PerformanceCounter element will be created for each performance counter in the category.

At present, turnOn is the only fact used by the framework to enable or disable the counter. You can touch this attribute any time (run-time as well), application pick up the changes and act accordingly.

If turnOn is true, the performance counter will be enabled. Otherwise it is disabled. This feature helps you to control the performance counter in the production environment as Performance Counters will affect your application performance.

Cinchoo – Using Performance Counters, Part 1

In this section I’ll discuss about how we can use Cinchoo framework’s performance counter helper class to gather data from an application. So we will first understand the fundamentals and then we will see a simple example from which we will collect some performance data.

Before we begin, if you like to know more information about Performance Counter, please visit below links

MSDN Performance Counter Class

An Article on Performance Counter in CodeProject

Cinchoo framework provides nifty performance counter helper classes to makes it easier for developers to develop applications that use Performance Counter to monitor the health of the application.

There are two types of Performance Counter Categories

  • SingleInstance – The performance counter category can have only a single instance.
  • MultipleInstance – The performance counter category can have multiple instances.

Creating and using SingleInstance Performance Counters

1. Add reference to Cinchoo.Core.dll assembly

2. Namespace Cinchoo.Core.Instrumentation.Performance

[ChoPerformanceCounterCategory("Random Single Instance Test", PerformanceCounterCategoryType.SingleInstance)]
public sealed class SingleInstancePerfCounters : ChoPerformanceCounterCategory
{
    #region Performance Counters

    [ChoPerformanceCounter("Random Rate", "", PerformanceCounterType.RateOfCountsPerSecond32)]
    public readonly ChoPerformanceCounter PCRandomRate = null;

    [ChoPerformanceCounter("Random Average", "", PerformanceCounterType.AverageCount64)]
    public readonly ChoPerformanceCounter PCRandomAverage = null;

    #endregion
}
 Now lets see how to instantiate and use them
[STAThread]
static void Main(string[] args)
{
    SingleInstancePerfCounters perfCounter = new SingleInstancePerfCounters();

    Random rand = new Random(42);
    int randMax = 100;

    while (true)
    {
        int r = rand.Next(randMax);

        if (perfCounter.PCRandomRate != null)
            perfCounter.PCRandomRate.Increment();
        if (perfCounter.PCRandomAverage != null)
            perfCounter.PCRandomAverage.IncrementBy(r);

        Thread.Sleep(1000);
    }
}

Creating and using MultipleInstance Performance Counters

1. Add reference to Cinchoo.Core.dll assembly

2. Namespace Cinchoo.Core.Instrumentation.Performance

[ChoPerformanceCounterCategory("Random Multiple Instance Test", PerformanceCounterCategoryType.MultiInstance)]
public sealed class MultipleInstancePerfCounters : ChoPerformanceCounterCategory
{
    #region Performance Counters

    [ChoPerformanceCounter("Random Value", "", PerformanceCounterType.NumberOfItems64, "Standard")]
    public readonly ChoPerformanceCounter PCRandomValue;

    [ChoPerformanceCounter("Random Value", "", PerformanceCounterType.NumberOfItems64, "Inverted")]
    public readonly ChoPerformanceCounter PCRandomInvertedValue;

    #endregion
}

Please remember that the above two Performance counter members are given same category name ‘Random Value’ and different instance names. It qualifies them to create multiple instances of performance counters.

Now lets see how to instantiate and use them

[STAThread]
static void Main(string[] args)
{
    MultipleInstancePerfCounters perfCounter = new MultipleInstancePerfCounters();

    Random rand = new Random(42);
    int randMax = 100;

    while (true)
    {
        int r = rand.Next(randMax);

        if (perfCounter.PCRandomValue != null)
            perfCounter.PCRandomValue.RawValue = r;
        if (perfCounter.PCRandomInvertedValue != null)
            perfCounter.PCRandomInvertedValue.RawValue = randMax - r;

        Thread.Sleep(1000);
    }
}

In the next part, will see how to control the Performance Counters through configuration.

Cinchoo – Configuration framework, part 14

Configuration Objects Logs

Cinchoo framework creates a  log file for each configuration object separately. Those log files are created under application binary folder. By default the log file name are generated from configuration object type full name.

For a sample configuration object below

namespace HelloWorld
{
	#region NameSpaces

	using System;
	using Cinchoo.Core.Configuration;

	#endregion NameSpaces

	[ChoConfigurationSection("sample")]
	public class SampleConfigSection : ChoConfigurableObject
	{
		#region Instance Data Members (Public)

		[ChoPropertyInfo("name", DefaultValue="Mark")]
		public string Name;

		[ChoPropertyInfo("message", DefaultValue="Hello World!")]
		public string Message;

		#endregion
	}
}

The log file will be created in the name of HelloWorld.SampleConfigSection.log under Application Bin/Settings folder.

2012-03-19 05:18:47.7648110
  -- HelloWorld.SampleConfigSection State --
	Name: Mark
	Message: Hello World!

-- MetaData Information --
	BindingMode: TwoWay
	Defaultable: True
	IgnoreError: True
	ConfigurationMetaDataLogInfo:
		-- Log Information --
			Condition: True
			TimeStampFormat:
			TraceOutputDirectory: Settings
			TraceOutputFileName: HelloWorld.SampleConfigSection.log

	ConfigStorageType: Cinchoo.Core.Configuration.Storage.ChoFileNameValueConfigStorage, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de

Application Log Folder can be overridden in both ways

  • Globally at the application level
  • Locally at each configuration object level

1. Overriding Global Log Folder

The application log folder can be overridden. Please visit Framework Configuration Parameters section on how to do it.

2. Overriding at individual configuration at object level

In some cases, you may want to redirect the log files of individual configuration object to some specific folder. In that moment, it can achieved as below.

namespace HelloWorld
{
	#region NameSpaces

	using System;
	using Cinchoo.Core.Configuration;

	#endregion NameSpaces

	[ChoConfigurationSection("sample", TraceOutputDirectory = @"C:\CustomLogsFolder")]
	public class SampleConfigSection : ChoConfigurableObject
	{
		#region Instance Data Members (Public)

		[ChoPropertyInfo("name", DefaultValue="Mark")]
		public string Name;

		[ChoPropertyInfo("message", DefaultValue="Hello World!")]
		public string Message;

		#endregion
	}
}

In this sample, we can route the log files of Configuration Object to C:/CustomLogsFolder directory using TraceOutputDirectory attribute member as below.

You can even override the individual configuration object log file through TraceOutputFileName attribute member as below

namespace HelloWorld
{
	#region NameSpaces

	using System;
	using Cinchoo.Core.Configuration;

	#endregion NameSpaces

	[ChoConfigurationSection("sample", TraceOutputDirectory = @"C:\CustomLogsFolder", TraceOutputFileName = "OverriddenSampleConfigObject.log")]
	public class SampleConfigSection : ChoConfigurableObject
	{
		#region Instance Data Members (Public)

		[ChoPropertyInfo("name", DefaultValue="Mark")]
		public string Name;

		[ChoPropertyInfo("message", DefaultValue="Hello World!")]
		public string Message;

		#endregion
	}
}

Cinchoo – Simplified Object Equality

In this post I present a way to implement equality between objects. Implicit support for == and != operators. There is the big writeup on Guidelines for Overloading Equals() and Operator == (C# Programming Guide) at MSDN that you can follow when you implement Equals() method for your custom type. But Cinchoo framework provides easy way to accomplish this. Read below on how to do it.

Reference Types

The Equals method is just a virtual one defined in System.Object, and overridden by whichever classes choose to do so. By default it provides reference equality.

The == operator is an operator which can be overloaded by classes, but which usually has identity behavior. The == operator has not been overloaded, it compares whether two references refer to the same object – which is exactly what the implementation of Equals does in System.Object.

Cinchoo framework provides abstraction through ChoEquatableObject<T> class, which exposes Equals() method, == and != operators for you. The default implementation of Equals() method uses reflection to make the comparison. This can be overloaded in your derived class.

1. Add reference to Cinchoo.Core.dll assembly

2. Namespace Cinchoo.Core

For the sample class derived from ChoEuatableObject<T>, uses the default implementation of object equality

public class Security : ChoEquatableObject<Security>
{
    public string Symbol;
    [ChoIgnoreEqual]
    public double Price;
    [ChoIgnoreEqual]
    public int Qty;
}

ChoIgnoreEqual tell the framework to ignore those members while making equality of the objects. In the above Security class, it only uses Symbol member while making equality and ignore other members.

If you worry about performance of using reflection when making equality of objects, you can consider overriding Equals() method as below

public class Security : ChoEquatableObject<Security>
{
    public string Symbol;
    public double Price;
    public int Qty;

    public override bool Equals(Security other)
    {
        if (object.ReferenceEquals(other, null))
            return false;

        return Symbol == other.Symbol;
    }
}

The sample test code below

class Program
{
    static void Main(string[] args)
    {
        Security sec1 = new Security() { Symbol="AAPL", Price = 555.10, Qty = 10 };
        Security sec2 = new Security() { Symbol="AAPL", Price = 655.55, Qty = 500 };

        Console.WriteLine("ChoObject.Equals() : " + ChoObject.Equals(sec1, sec2));
        Console.WriteLine("Object.Equals() : " + sec1.Equals(sec2));
        Console.WriteLine("== operator: " + (sec1 == sec2));
        Console.WriteLine("!= operator: " + (sec1 != sec2));
    }
}

The output will be

ChoObject.Equals() : True
Object.Equals() : True
== operator: True
!= operator: False

In cases where you do not want to derive from ChoEquableObject<T> or your class already in the inheritance chain, please follow the next section in implementing object equality.

Value Types

Value types do not provide an overload for == by default. However, most of the value types provided by the framework provide their own overload. The default implementation of Equals for a value type is provided by ValueType , and uses reflection to make the comparison.

Below is the way to implement ValueType equality or a reference type equality through Interface

public struct Security : IEquatable<Security>
{
    public string Symbol;
    public double Price;
    public int Qty;

    #region IEquatable<Security> Members

    public override bool Equals(object obj)
    {
        return Equals((Security)obj);
    }

    public bool Equals(Security other)
    {
        if (object.ReferenceEquals(other, null))
            return false;

        return Symbol == other.Symbol;
    }

    public static bool operator ==(Security a, Security b)
    {
        return ChoObject.Equals(a, b);
    }

    public static bool operator !=(Security a, Security b)
    {
        return !ChoObject.Equals(a, b);
    }

    #endregion
}


Cinchoo – Configuration framework, part 13

Managing Large Configuration file

Download sample source files (Require .NET 4.0 / Visual Studio 2010)

Suppose in a large application built on several components packaged in their own assemblies, managing configuration file in one file will be tedious. Using Cinchoo configuration framework, you can split them into manageable small files. I’ll walk you over the steps to split them and use them in a application.

There are couple of ways, you can achieve the splitting of configuration files

1. Automatic Split (Code first approach)

This approach is viable in case of new development where there are no existing configuration files available.  In this scenario, you just design and implement the configuration objects first and let the Cinchoo framework generate the configuration files for you. I’ll walk you over on how to do it using this approach.

You can specify the individual configuration file for each configuration object using ChoConfigurationSectionAttribute, where you must give the name of the configuration file in one of the property

  • ConfigFilePath – Configuration file path in string either full path or just file name.
  • ConfigFilePathFromTypeName – For a given type specified to this property, it takes the name of the type as configuration file name.
  • ConfigFilePathFromTypeFullName – For a given type specified to this property, it takes the fully qualified namespace name of the type as configuration file name.

For a sample console application named SplitConfigUsingCodeFirstApproach.exe, defining the below two configuration objects

[ChoNameValueConfigurationSection("serverDetails/environments", ConfigFilePathFromTypeName = typeof(ServerEnvironments))]
public class ServerEnvironments : ChoConfigurableObject
{
    public string Host = "WNYC1000234011";
    public string IP = "205.12.5.122";
    public int Port = 2001;
}

[ChoNameValueConfigurationSection("applicationSettings", ConfigFilePath = "ApplicationSettings" )]
public class ApplicationSettings : ChoConfigurableObject
{
    public string Mode = "LIVE";
    public bool IsConnected = true;
    public string Exchange = "NYSE";
}

Just instantiate the above objects in the Main entry method as below, Cinchoo framework creates the configuration files automatically.

class Program
{
    static void Main(string[] args)
    {
        ServerEnvironments serverEnvironments = new ServerEnvironments();
        ApplicationSettings applicationSettings = new ApplicationSettings();

        ChoFramework.Shutdown();
    }
}

The main application configuration file (SplitConfigUsingCodeFirstApproach.exe.xml)  is generated as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <applicationSettings cinchoo:path="C:\CinchooConfigurationFrxDemos\SplitConfigUsingCodeFirstApproach\SplitConfigUsingCodeFirstApproach\bin\Debug\ApplicationSettings.xml" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
  <serverDetails>
    <environments cinchoo:path="C:\CinchooConfigurationFrxDemos\SplitConfigUsingCodeFirstApproach\SplitConfigUsingCodeFirstApproach\bin\Debug\ServerEnvironments.xml" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
  </serverDetails>
</configuration>

And the splitted configuration files corresponding to two configuration objects defined in the code are generated automatically by the framework.

For the ServerEnvironments object, the file named ServerEnvironments.xml is generated as below

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="serverDetails">
      <section name="environments" type="Cinchoo.Core.Configuration.Handlers.ChoNameValueSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
    </sectionGroup>
  </configSections>
  <serverDetails>
    <environments>
      <add key="Host" value="WNYC1000234011" />
      <add key="IP" value="205.12.5.122" />
      <add key="Port" value="2001" />
    </environments>
  </serverDetails>
</configuration>

For the ApplicationSettings object, the file named ApplicationSettings.xml is generated as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="applicationSettings" type="Cinchoo.Core.Configuration.Handlers.ChoNameValueSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
  </configSections>
  <applicationSettings>
    <add key="Mode" value="LIVE" />
    <add key="IsConnected" value="True" />
    <add key="Exchange" value="NYSE" />
  </applicationSettings>
</configuration>

For any reason, the configuration files needs to be re-created, all you have to do is delete the configuration files or removing the configuration sections from the configuration file will trigger the Cinchoo framework to regenerate them seamlessly.

2. Manual Step (Configuration model first approach)

This approach is suitable if you already have established configuration file, you can use this method to split them.

Lets say, you have application configuration file named HelloWorld.exe.xml 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="serverDetails" type="Cinchoo.Core.Configuration.Handlers.ChoNameValueSectionHandler, Cinchoo.Core" />
        <sectionGroup name="allSections">
            <section name="sample" type="Cinchoo.Core.Configuration.Handlers.ChoXmlSerializerSectionHandler, Cinchoo.Core" />
        </sectionGroup>
    </configSections>
    <serverDetails Name="Mark">
        <Message>Hello World!</Message>
    </serverDetails>
    <allSections>
        <sample Name="Mark">
            <Message>Hello World!</Message>
        </sample>
    </allSections>
</configuration>

Above configuration file contains two sections ‘serverDetails’ and ‘allSections/sample’. I’m going to split this file into two files and show you how to link them together in the main configuration file.

The main configuration file HelloWorld.exe.xml will look as below after the split

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <serverDetails cinchoo:path="ServerDetails.xml" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
    <allSections>
        <sample cinchoo:path="Sample.xml" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
    </allSections>
</configuration>

The splitted configuration files ServerDetails.xml and Sample.xml files will look below

ServerDetails.xml

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="serverDetails" type="Cinchoo.Core.Configuration.Handlers.ChoXmlSerializerSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
    </configSections>
    <serverDetails Name="Mark">
        <Message>Hello World!</Message>
    </serverDetails>
</configuration>

Sample.xml

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="allSections">
            <section name="sample" type="Cinchoo.Core.Configuration.Handlers.ChoXmlSerializerSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
        </sectionGroup>
    </configSections>
    <allSections>
        <sample Name="Mark">
            <Message>Hello World!</Message>
        </sample>
    </allSections>
</configuration>

Cinchoo – Configuration framework, part 12

Using ChoFileXmlSerializerConfigStorage

Download sample source files (Require .NET 4.0 / Visual Studio 2010)

In this section, I’ll go over the details of using ChoFileXmlSerializerConfigStorage in your application. It’s a custom configuration section handler enables application to read and write application settings from configuration file in complex Xml format.

1. Define the configuration section object decorated with ChoXmlSerializerConfigurationSectionAttribute as below.

[ChoXmlSerializerConfigurationSection("sample")]
public class SampleConfigSection : ChoConfigurableObject
{
    #region Instance Data Members (Public)

    [XmlAttribute]
    public string Name;

    [XmlElement]
    public string Message;

    #endregion

    [ChoAfterConfigurationObjectLoadedHandler]
    void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
    {
        Console.WriteLine(sender.ToString());
    }
}

2. Now instantiate and use it as below.

class Program
{
	static void Main(string[] args)
	{
		SampleConfigSection sampleConfigSection = new SampleConfigSection();
		Console.WriteLine(sampleConfigSection.ToString());
	}
}

The configuration section will be generated automatically for the first time in HelloWorld.exe.xml as below.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <sample Name="Mark">
    <Message>Hello World!</Message>
  </sample>
  <configSections>
    <section name="sample" type="Cinchoo.Core.Configuration.ChoXmlSerializerSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
  </configSections>
</configuration>

Cinchoo – Read from console with timeout

You have a console application in which you want to give the user number of seconds to respond to the prompt. If no input is made after a certain period of time, program should continue.

Cinchoo framework provides this through ChoConsole class.

1. Add reference to Cinchoo.Core.dll assembly

2. Namespace Cinchoo.Core.Shell.Console

Below are the following methods

Read() Overloads:

This method reads the next character from the standard input stream either within the specified timeout period or infinity.

public static int Read(int timeoutInMilliSeconds);
public static int Read(int timeoutInMilliSeconds, int? defaultValue);
public static int Read(int timeoutInMilliSeconds, int? defaultValue, string errMsg)

ReadLine() Overloads:

This method reads the next line of characters from the standard input stream either within the specified timeout period or infinity.

public static int ReadLine(int timeoutInMilliSeconds);
public static int ReadLine(int timeoutInMilliSeconds, int? defaultValue);
public static int ReadLine(int timeoutInMilliSeconds, int? defaultValue, string errMsg)

ReadKey() Overloads:

This method reads the next character from the standard input stream either within the specified timeout period or infinity.

public static ConsoleKeyInfo ReadKey(int timeoutInMilliSeconds);
public static ConsoleKeyInfo ReadKey(int timeoutInMilliSeconds, int? defaultValue);
public static ConsoleKeyInfo ReadKey(int timeoutInMilliSeconds, int? defaultValue, string errMsg)

Cinchoo – Configuration framework, part 11

Configuration member value conversion

Wonder how to convert configuration member value from source type to target type. Cinchoo configuration framework provides couple of ways to convert the values.

1. Using TypeConverter in declarative way

2. Using callback event mechanism

Using TypeConverter

You can use .NET Type converters, Cinchoo framework TypeConverters or create your own TypeConverters in declarative way as below

[ChoConfigurationSection("sample/appSettings")]
public class AppSettings : ChoConfigurableObject
{
    [ChoPropertyInfo("Trader", DefaultValue = "Mark")]
    public string Trader
    {
        get;
        set;
    }

    [ChoPropertyInfo("Securities", DefaultValue = "AAPL; GOOG; IBM")]
    [ChoTypeConverter(typeof(ChoStringToStringArrayConverter), Parameter = (object)',')]
    public string[] Securities
    {
        get;
        set;
    }

    [ChoAfterConfigurationObjectLoadedHandler]
    void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
    {
        Console.WriteLine(sender.ToString());
        Console.WriteLine("Securities Length: " + Securities.Length.ToString());
    }
}

class Program
{
    static void Main(string[] args)
    {
            AppSettings appSettings = new AppSettings();
    }
}

Output will be

-- ConfigApp.AppSettings State --
        Trader: Mark
        Securities: AAPL, GOOG, IBM

Securities Length: 3

Press any key to continue . . .

Using callback event

Some cases where there are no TypeConverters available to do the value conversion or you may want to carry extra operations while doing type conversion, you can use this approach. You can use ChoBeforeConfigurationObjectMemberLoadedHandler to carry out the member conversion. See below the sample

[ChoConfigurationSection("sample/appSettings")]
public class AppSettings : ChoConfigurableObject
{
    [ChoPropertyInfo("Trader", DefaultValue = "Mark")]
    public string Trader
    {
        get;
        set;
    }

    [ChoPropertyInfo("Securities", DefaultValue = "AAPL; GOOG; IBM")]
    public string[] Securities
    {
        get;
        set;
    }

    [ChoBeforeConfigurationObjectMemberLoadedHandler]
    void OnBeforeConfigurationObjectMemberLoadedHandler(object sender, ChoPreviewConfigurationObjectMemberEventArgs e)
    {
        if (e.MemberName == "Securities")
            e.State= e.OriginalState.ToString().SplitNTrim(';');
    }

    [ChoAfterConfigurationObjectLoadedHandler]
    void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
    {
        Console.WriteLine(sender.ToString());
        Console.WriteLine("Securities Length: " + Securities.Length.ToString());
    }
}

class Program
{
    static void Main(string[] args)
    {
            AppSettings appSettings = new AppSettings();
    }
}

Output will be

-- ConfigApp.AppSettings State --
        Trader: Mark
        Securities: AAPL, GOOG, IBM

Securities Length: 3

Press any key to continue . . .
Corresponding configuration section will be created automatically in applicationName.exe.xml file as below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="sample">
      <section name="appSettings" type="Cinchoo.Core.Configuration.Handlers.ChoNameValueSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
    </sectionGroup>
  </configSections>
  <sample>
    <appSettings>
      <add key="Trader" value="Mark" />
      <add key="Securities" value="AAPL; GOOG; IBM1" />
    </appSettings>
  </sample>
</configuration>

Cinchoo – .NET TypeConverters

List of TypeConverters

Below are the list of .NET TypeConverters available, these can be used in Cinchoo framework in various places i.e ChoObject.ToString(), ConfigurationManagement etc

Microsoft.VisualBasic.Activities.XamlIntegration.VisualBasicSettingsConverter
Microsoft.VisualBasic.ApplicationServices.BuiltInRoleConverter
System.Activities.XamlIntegration.TypeConverterBase
System.ComponentModel.BaseNumberConverter
System.ComponentModel.BooleanConverter
System.ComponentModel.CharConverter
System.ComponentModel.CollectionConverter
System.ComponentModel.CultureInfoConverter
System.ComponentModel.DateTimeConverter
System.ComponentModel.DateTimeOffsetConverter
System.ComponentModel.EnumConverter
System.ComponentModel.ExpandableObjectConverter
System.ComponentModel.GuidConverter
System.ComponentModel.MultilineStringConverter
System.ComponentModel.NullableConverter
System.ComponentModel.ReferenceConverter
System.ComponentModel.StringConverter
System.ComponentModel.TimeSpanConverter
System.ComponentModel.TypeListConverter
System.Configuration.ConfigurationConverterBase
System.Diagnostics.Design.LogConverter
System.Drawing.ColorConverter
System.Drawing.FontConverter
System.Drawing.FontConverter.FontNameConverter
System.Drawing.ImageConverter
System.Drawing.ImageFormatConverter
System.Drawing.PointConverter
System.Drawing.RectangleConverter
System.Drawing.SizeConverter
System.Drawing.SizeFConverter
System.Resources.ResXFileRef.Converter
System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicyTypeConverter
System.ServiceModel.Discovery.Configuration.DiscoveryVersionConverter
System.ServiceModel.XamlIntegration.EndpointIdentityConverter
System.ServiceModel.XamlIntegration.ServiceXNameTypeConverter
System.ServiceModel.XamlIntegration.XPathMessageContextTypeConverter
System.UriTypeConverter
System.Web.Configuration.LowerCaseStringConverter
System.Web.UI.Design.DataBindingCollectionConverter
System.Web.UI.Design.DataColumnSelectionConverter
System.Web.UI.Design.DataFieldConverter
System.Web.UI.Design.DataMemberConverter
System.Web.UI.Design.DataSourceConverter
System.Web.UI.Design.DataSourceViewSchemaConverter
System.Web.UI.Design.ExpressionsCollectionConverter
System.Web.UI.Design.MobileControls.Converters.DataFieldConverter
System.Web.UI.Design.MobileControls.Converters.DataMemberConverter
System.Web.UI.Design.SkinIDTypeConverter
System.Web.UI.Design.WebControls.DataSourceIDConverter
System.Web.UI.WebControls.FontNamesConverter
System.Web.UI.WebControls.FontUnitConverter
System.Web.UI.WebControls.StringArrayConverter
System.Web.UI.WebControls.UnitConverter
System.Windows.Controls.DataGridLengthConverter
System.Windows.CornerRadiusConverter
System.Windows.CultureInfoIetfLanguageTagConverter
System.Windows.DeferrableContentConverter
System.Windows.DialogResultConverter
System.Windows.DurationConverter
System.Windows.DynamicResourceExtensionConverter
System.Windows.ExpressionConverter
System.Windows.FigureLengthConverter
System.Windows.FontSizeConverter
System.Windows.FontStretchConverter
System.Windows.FontStyleConverter
System.Windows.FontWeightConverter
System.Windows.Forms.AxHost.StateConverter
System.Windows.Forms.CursorConverter
System.Windows.Forms.DataGridPreferredColumnWidthTypeConverter
System.Windows.Forms.DataGridViewCellStyleConverter
System.Windows.Forms.KeysConverter
System.Windows.Forms.Layout.TableLayoutSettingsTypeConverter
System.Windows.Forms.LinkArea.LinkAreaConverter
System.Windows.Forms.LinkConverter
System.Windows.Forms.ListBindingConverter
System.Windows.Forms.OpacityConverter
System.Windows.Forms.PaddingConverter
System.Windows.Forms.ScrollableControl.DockPaddingEdgesConverter
System.Windows.Forms.SelectionRangeConverter
System.Windows.Forms.TreeNodeConverter
System.Windows.GridLengthConverter
System.Windows.Input.CommandConverter
System.Windows.Input.CursorConverter
System.Windows.Input.InputScopeConverter
System.Windows.Input.InputScopeNameConverter
System.Windows.Input.KeyConverter
System.Windows.Input.KeyGestureConverter
System.Windows.Input.ModifierKeysConverter
System.Windows.Input.MouseActionConverter
System.Windows.Input.MouseGestureConverter
System.Windows.Int32RectConverter
System.Windows.KeySplineConverter
System.Windows.KeyTimeConverter
System.Windows.LengthConverter
System.Windows.Markup.DependencyPropertyConverter
System.Windows.Markup.EventSetterHandlerConverter
System.Windows.Markup.NameReferenceConverter
System.Windows.Markup.RoutedEventConverter
System.Windows.Markup.SetterTriggerConditionValueConverter
System.Windows.Markup.TemplateKeyConverter
System.Windows.Markup.XmlLanguageConverter
System.Windows.Media.Animation.RepeatBehaviorConverter
System.Windows.Media.BrushConverter
System.Windows.Media.CacheModeConverter
System.Windows.Media.ColorConverter
System.Windows.Media.Converters.BaseIListConverter
System.Windows.Media.DoubleCollectionConverter
System.Windows.Media.FontFamilyConverter
System.Windows.Media.GeometryConverter
System.Windows.Media.ImageSourceConverter
System.Windows.Media.Int32CollectionConverter
System.Windows.Media.MatrixConverter
System.Windows.Media.Media3D.Matrix3DConverter
System.Windows.Media.Media3D.Point3DCollectionConverter
System.Windows.Media.Media3D.Point3DConverter
System.Windows.Media.Media3D.Point4DConverter
System.Windows.Media.Media3D.QuaternionConverter
System.Windows.Media.Media3D.Rect3DConverter
System.Windows.Media.Media3D.Size3DConverter
System.Windows.Media.Media3D.Vector3DCollectionConverter
System.Windows.Media.Media3D.Vector3DConverter
System.Windows.Media.PathFigureCollectionConverter
System.Windows.Media.PixelFormatConverter
System.Windows.Media.PointCollectionConverter
System.Windows.Media.RequestCachePolicyConverter
System.Windows.Media.TransformConverter
System.Windows.Media.VectorCollectionConverter
System.Windows.PointConverter
System.Windows.PropertyPathConverter
System.Windows.RectConverter
System.Windows.SizeConverter
System.Windows.StrokeCollectionConverter
System.Windows.TemplateBindingExpressionConverter
System.Windows.TemplateBindingExtensionConverter
System.Windows.TextDecorationCollectionConverter
System.Windows.ThicknessConverter
System.Windows.VectorConverter
System.Workflow.ComponentModel.Design.ActivityBindTypeConverter
System.Xaml.Schema.XamlTypeTypeConverter


	

Cinchoo – ChoObject.ToString(), Part 9

Ignoring members

An object members decorated with ChoMemberFormatterIgnore will be ignored by Cinchoo framework 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;
    [ChoMemberFormatterIgnore]
    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 will be

-- 'AAPL' Security State --
        Symbol: AAPL
        CompanyName: Apple Inc

Press any key to continue . . .

Happy coding!!!