当前位置: 首页>>代码示例>>C#>>正文


C# Options.Initialize方法代码示例

本文整理汇总了C#中Options.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# Options.Initialize方法的具体用法?C# Options.Initialize怎么用?C# Options.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Options的用法示例。


在下文中一共展示了Options.Initialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        /// <summary>
        /// Generates HTML file from XSLT and XML documents,
        /// converts CSS styles to the inline definitions, and 
        /// cleans up HTML code and formats the file 
        /// (the last two steps are optional).
        /// </summary>
        /// <param name="args">
        /// Command-line arguments.
        /// </param>
        /// <returns>
        /// <c>0</c> (zero) on success, <c>-1</c> on failure.
        /// </returns>
        static int Main(
			string[] args
		)
        {
            // Indicates program success or failure.
            bool success = true;

            // Used to parse command line.
            CommandLineParser parser = null;

            try
            {
                // Parse command line.
                _options = new Options();
                parser = new CommandLineParser(_options);

                parser.Parse();

                // If help switch (/h|/?|/help) is provided
                if (_options.Help)
                {
                    // Display help usage info.
                    Console.WriteLine(parser.UsageInfo.ToString(
                        Console.WindowWidth, false));

                    Console.WriteLine("For additional information, see:");
                    Console.WriteLine("https://github.com/alekdavis/XslMail");

                    return 0;
                }

                // If there are problems with provided switches
                if (parser.HasErrors)
                {
                    // Display error info.
                    Console.WriteLine(parser.UsageInfo.GetErrorsAsString(
                        Console.WindowWidth));
                    return -1;
                }

                // Finalize initialization of the application options.
                // This call will check if the program is invoked
                // without the command-line switches and if so
             				// read settings from the .config file.
                // It will also adjust the default settings for the
                // application runtime context (working folder, etc).
                _options.Initialize(args);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Cannot initialize.");
                Console.Error.WriteLine(GetErrorMessage(ex));

                return -1;
            }

            // If optional error log file is specified, open it.
            try
            {
                if (!String.IsNullOrEmpty(_options.ErrorFile))
                    _errFile = OpenFile(_options.ErrorFile);
            }
            catch(Exception ex)
            {
                Console.Error.WriteLine(
                    "Cannot initialize error file '" +
                    _options.ErrorFile + "'.");
                Console.Error.WriteLine(GetErrorMessage(ex));

                if (_logFile != null)
                    _logFile.Close();

                return -1;
            }

            // If optional log file is specified, open it.
            try
            {
                if (!String.IsNullOrEmpty(_options.LogFile))
                {
                    _logFile = OpenFile(_options.LogFile);
                }
            }
            catch(Exception ex)
            {
                Console.Error.WriteLine(
                    "Cannot initialize log file '" +
                    _options.LogFile + "'.");
//.........这里部分代码省略.........
开发者ID:alekdavis,项目名称:XslMail,代码行数:101,代码来源:Program.cs


注:本文中的Options.Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。