static void ShowSectionInfo()
        {
            SampleSection customSection =
                ConfigurationManager.GetSection("custom") as SampleSection;

            if (customSection == null)
            {
                Console.WriteLine("Failed to load SampleSection.");
            }
            else
            {
                Console.WriteLine("Section Information:");

                Console.WriteLine("  Name: {0}",
                                  customSection.SectionInformation.Name);

                Console.WriteLine("  SectionName: {0}",
                                  customSection.SectionInformation.SectionName);

                Console.WriteLine("  Type: {0}",
                                  customSection.SectionInformation.Type);

                Console.WriteLine("  AllowDefinition: {0}",
                                  customSection.SectionInformation.AllowDefinition);

                Console.WriteLine("  AllowExeDefinition: {0}",
                                  customSection.SectionInformation.AllowExeDefinition);
            }
        }
        static void ShowDefaults()
        {
            SampleSection customSection =
                ConfigurationManager.GetSection("custom") as SampleSection;

            if (customSection == null)
            {
                Console.WriteLine("Failed to load SsmpleSection.");
            }
            else
            {
                Console.WriteLine("Defaults:");
                Console.WriteLine("  File Name: {0}",
                                  customSection.FileName);
                Console.WriteLine("  Max Users: {0}",
                                  customSection.MaxUsers);
                Console.WriteLine("  Max Idle Time: {0}",
                                  customSection.MaxIdleTime);
                Console.WriteLine("  Last access: {0}",
                                  customSection.LastAccess);
                Console.WriteLine("  Alias 1: {0}",
                                  customSection.Alias);
                Console.WriteLine("  Alias 2: {0}",
                                  customSection.Alias2);
            }
        }
 static void Main(string[] args)
 {
     Console.WriteLine("[Current Defaults]");
     ShowDefaults();
     Console.WriteLine();
     //SampleSection.DisplayTimeSpanAbsoluteRange();
     //SampleSection.TimeStampValidatorInstance();
     //SampleSection.IntegerValidatorInstance();
     //SampleSection.StringValidatorInstance();
     SampleSection.RegexStringValidatorInstance();
     Console.ReadLine();
 }
        static void DisplaySectionProperties()
        {
            SampleSection sampleSection =
                ConfigurationManager.GetSection("MyDailyProcess") as SampleSection;

            if (sampleSection == null)
            {
                Console.WriteLine("Failed to load section.");
            }
            else
            {
                Console.WriteLine("Defaults:");
                Console.WriteLine("  Name: {0}", sampleSection.Name);
                Console.WriteLine("  BuildStartTime: {0}", sampleSection.BuildStartTime);
                Console.WriteLine("  BuildEndTime: {0}", sampleSection.BuildEndTime);
            }
        }
        // Shows how to use the ValidatorInstance method.
        public static void GetCustomValidatorInstance()
        {
            ConfigurationValidatorBase valBase;
            CustomValidatorAttribute   customValAttr;

            customValAttr = new CustomValidatorAttribute();

            SampleSection sampleSection =
                ConfigurationManager.GetSection("MyDailyProcess") as SampleSection;

            TimeSpanConverter myTSC          = new TimeSpanConverter();
            TimeSpan          StartTimeSpan  = (TimeSpan)myTSC.ConvertFromString(sampleSection.BuildStartTime.ToString());
            TimeSpan          EndTimeSpan    = (TimeSpan)myTSC.ConvertFromString(sampleSection.BuildEndTime.ToString());
            TimeSpan          resultTimeSpan = EndTimeSpan - StartTimeSpan;

            try
            {
                // <Snippet3>
                // Determine if the Validator can validate
                // the type it contains.
                valBase = customValAttr.ValidatorInstance;
                if (valBase.CanValidate(resultTimeSpan.GetType()))
                {
                    // <Snippet4>
                    // Validate the TimeSpan using a
                    // custom PositiveTimeSpanValidator.
                    valBase.Validate(resultTimeSpan);
                    // </Snippet4>
                }
                // </Snippet3>
            }
            catch (ArgumentException e)
            {
                // Store error message.
                string msg = e.Message.ToString();
#if DEBUG
                Console.WriteLine("Error: {0}", msg);
#endif
            }
        }
        // Create required sections.
        static void CreateSection()
        {
            // Get the current configuration (file).
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Define the sample section.
            SampleSection sampleSection;

            // Create the handler section named MyDailyProcess
            // in the <configSections>. Also, create the
            // <MyDailyProcess> target section
            // in <configuration>.
            if (config.Sections["MyDailyProcess"] == null)
            {
                sampleSection = new SampleSection();
                config.Sections.Add("MyDailyProcess", sampleSection);
                sampleSection.SectionInformation.ForceSave = true;
                config.Save(ConfigurationSaveMode.Full);
            }
        }