本文整理汇总了C#中Parameter.WithValue方法的典型用法代码示例。如果您正苦于以下问题:C# Parameter.WithValue方法的具体用法?C# Parameter.WithValue怎么用?C# Parameter.WithValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameter
的用法示例。
在下文中一共展示了Parameter.WithValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanBuildWithOverridingParameters
public void CanBuildWithOverridingParameters()
{
var args = new RemoteBounceArguments() {Targets = new [] {"One"}};
var param1 = new Parameter<string> {Name = "name1"};
var param2 = new Parameter<string> { Name = "name2" };
var argsWithParam1 = args.WithParameter(param1.WithValue("value1"));
var argsWithParam2 = args.WithParameter(param2.WithValue("value2"));
Assert.That(argsWithParam1.Parameters.Count(), Is.EqualTo(1));
Assert.That(argsWithParam1.Parameters.ElementAt(0).Name, Is.EqualTo("name1"));
Assert.That(((Parameter<string>) argsWithParam1.Parameters.ElementAt(0)).Value, Is.EqualTo("value1"));
Assert.That(argsWithParam2.Parameters.Count(), Is.EqualTo(1));
Assert.That(argsWithParam2.Parameters.ElementAt(0).Name, Is.EqualTo("name2"));
Assert.That(((Parameter<string>) argsWithParam2.Parameters.ElementAt(0)).Value, Is.EqualTo("value2"));
Assert.That(args.Parameters, Is.Empty);
}
示例2: RenderValue
private Parameter RenderValue(string context, string content)
{
object value;
var param = new Parameter();
if (content.IsNullOrWhitespace())
{
return param.WithValue(content);
}
else if (TryFillParameter(content, param) && TryGetParamValue(param.Name, out value))
{
if (param.IsRaw) return param.WithValue((value ?? "").ToString());
switch (context)
{
case "idlist":
return param.WithValue(RenderSqlEnum(value, false, o => _context.Format(o)));
case "in":
case "not in":
return param.WithValue(RenderSqlEnum(value, true, o => _context.Format(o)));
case "like":
case "not like":
// Do something useful with context
return param.WithValue(RenderSqlEnum(value, false, o => _context.Format(o)));
default:
return param.WithValue(RenderSqlEnum(value, false, o => _context.Format(o)));
}
}
else if (context == "between" || context == "not between")
{
// Do something useful here
return param.WithValue(content);
}
else if (context == "sql"
|| context == "where")
{
return param.WithValue(SqlReplace(content));
}
else if ((context == "in" || context == "not in")
&& content.TrimStart()[0] == '(')
{
content = content.Trim();
if (content.Length > 2 && content[1] == '@')
{
// Dapper is trying to be too helpful with parameter expansion
return param.WithValue(SqlReplace(content.TrimStart('(').TrimEnd(')')));
}
else
{
return param.WithValue(SqlReplace(content));
}
}
else
{
return param.WithValue(content);
}
}
示例3: Main
static void Main(string[] args)
{
var inputFile = new Parameter<FileInfo>
{
ShortName = "i",
LongName = "input",
ValueName = "filename",
Description = "The path of the input file.",
};
var outputFile = new Parameter<FileInfo>()
{
ShortName = "o",
LongName = "output",
ValueName = "filename",
Description = "The path of the output file.",
};
var playingOption = new Parameter<PlayingOption>()
{
ShortName = "p",
LongName = "playing-option",
Description = "The options for playing.",
};
var randomNumbers = new ParameterList<double>
{
ShortName = "r",
LongName = "random",
Description = "Random numbers.",
};
var fast = new Parameter<bool>
{
ShortName = "f",
LongName = "fast",
Description = "Make it fast.",
};
var culture = new Parameter<CultureInfo>
{
ShortName = "cu",
LongName = "culture",
Description = "The culture.",
IsOptional = true,
DefaultValue = CultureInfo.InvariantCulture
};
var count = new Parameter<int>()
{
ShortName = "c",
LongName = "count",
Description = "Count of something.",
IsOptional = true,
DefaultValue = 1,
PossibleValues = { 1, 2, 3, 4, 5 },
StaticContextParameters =
{
randomNumbers
}
};
var commandLine = new CommandLine
{
ProgramName = "sarcasmizer",
Description = "This is a good program.",
Parameters =
{
inputFile,
outputFile,
playingOption,
count,
fast,
culture
},
Examples =
{
new Example
{
Parameters =
{
inputFile.WithValue(new FileInfo("foo.txt")),
outputFile.WithValue(new FileInfo("bar.txt"))
},
Description = "Simple example."
},
new Example
{
Parameters =
{
inputFile.WithValue(new FileInfo("foo.txt")),
outputFile.WithValue(new FileInfo("bar.txt")),
count.WithValue(8)
},
Description = "Example."
},
new Example
//.........这里部分代码省略.........