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


C# ConnectionString.Any方法代码示例

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


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

示例1: Config

        private Config(string[] args)
        {
            Provider? p = null;
            new OptionSet { { "providerName=", "", s => p = new Provider(s) } }.Parse(args);

            var provider = p ?? Provider.Default;

            string output = null;
            bool scalar = false, nonquery = false, help = false;
            var commandLine = new CommandLine();
            var connectionString = new ConnectionString();

            Action<CommandLineParam, string> setCommandLineValue = (cl, s) => commandLine[cl] = Value.From(s.Trim('"'));

            Func<string, string, bool> onUnknownOption = (name, value) =>
            {
                connectionString[new ConnectionStringParam(name.Trim('"'))] = Value.From(value.Trim('"'));
                return true;
            };

            var options = new MyOptionSet(
                CommandLineToConnectionString(provider), 
                setCommandLineValue,
                onUnknownOption)
            {
                {
                    "output=",
                    "Path to output File. If none specified, output is written to the console.",
                    s => output = s
                },
                {
                    "scalar",
                    "Interpret the query as a scalar result, i.e. a single value (of any type)",
                    s => scalar = true
                },
                {
                    "nonquery",
                    "Run the query as a 'non-select' statement, i.e. INSERT, UPDATE, DELETE or a DDL statement. " +
                    "Outputs the number of affected records of the last statement.",
                    s => nonquery = true
                },
                {
                    "providerName=",
                    "The db provider name.",
                    s => provider = new Provider(s)
                },
                {
                    "help",
                    "Print this text.",
                    s => help = true
                }
            };


            var remaining = options.Parse(args);

            Output = output;
            Scalar = scalar;
            NonQuery = nonquery;
            Help = help;
            _provider = provider;
            _optionSet = options;

            if (remaining.Any())
            {
                var queryOrFileName = remaining.First();
                Query = File.Exists(queryOrFileName) ? File.ReadAllText(queryOrFileName) : queryOrFileName;
            }

            if (commandLine.Any() || connectionString.Any())
            {
                ConnectionString = GetConnectionString(_provider, commandLine, connectionString);
            }
            else
            {
                var settings = ConnectionStrings["Default"];
                if (settings == null) 
                    throw new ConnectionConfigException("No connection configuration found. Either provide command line parameters, or add a .config file with a connection string named 'Default'");
                ConnectionString = settings.ConnectionString;
                _provider = new Provider(settings.ProviderName);
            }
        }
开发者ID:jhgbrt,项目名称:SqlConsole,代码行数:82,代码来源:Config.cs


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