本文整理汇总了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);
}
}