本文整理汇总了C#中Optional.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Optional.Select方法的具体用法?C# Optional.Select怎么用?C# Optional.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Optional
的用法示例。
在下文中一共展示了Optional.Select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Select_returns_new_option_with_mapped_value_when_called_on_Some
public void Select_returns_new_option_with_mapped_value_when_called_on_Some()
{
var enclosedValue = Guid.NewGuid().ToString();
var some = new Optional<string>(enclosedValue);
var expected = new Optional<int>(enclosedValue.Length);
var actual = some.Select(s => s.Length);
Assert.That(actual, Is.EqualTo(expected));
}
示例2: Select_returns_None_when_called_on_None
public void Select_returns_None_when_called_on_None()
{
var none = new Optional<string>(null);
var expected = Optional<int>.None;
var actual = none.Select(s => s.Length);
Assert.That(actual, Is.EqualTo(expected));
}
示例3: Create
public Optional<string> Create(Optional<string> directory)
{
if (!Skip)
{
var name = Name.Select(n => n, () => "");
var nuspecId = "boost_" + name;
var srcFiles =
FileList.Select(
f =>
new Nuspec.File(
directory.Select(d => Path.Combine(d, f), () => f),
Path.Combine(Targets.SrcPath, f)
)
);
//
foreach (var u in CompilationUnitList)
{
u.Make(this);
}
//
var clCompile =
new Targets.ClCompile(
preprocessorDefinitions:
PreprocessorDefinitions.
Concat(new[] { nuspecId.ToUpper() + "_NO_LIB" }).
ToOptionalClass()
);
Nuspec.Create(
nuspecId,
nuspecId,
Config.Version,
nuspecId,
new[]
{
new Targets.ItemDefinitionGroup(clCompile: clCompile)
},
srcFiles,
CompilationUnitList,
BoostDependency,
new[] { "sources", name }
);
return Name;
}
else
{
return Optional<string>.Absent.Value;
}
}