本文整理汇总了C#中Maybe.Map方法的典型用法代码示例。如果您正苦于以下问题:C# Maybe.Map方法的具体用法?C# Maybe.Map怎么用?C# Maybe.Map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Maybe
的用法示例。
在下文中一共展示了Maybe.Map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Map_hello_hella
public void Map_hello_hella()
{
//Arrange
Maybe<string> opt = new Maybe<string>("hello");
//Act
Maybe<string> optResult = opt.Map(str => str.Replace("o", "a"));
//Assert
Logger.Debug("result: " + optResult.Get());
Assert.AreEqual("hella", optResult.Get());
}
示例2: Map_null_empty
public void Map_null_empty()
{
//Arrange
Maybe<string> opt = new Maybe<string>(null);
//Act
Maybe<string> optResult = opt
.Map(str => str.Replace("o", "a"))
.Map(str => str.Replace("l", "n"));
//Assert
Logger.Debug("result: " + optResult.Get());
Assert.AreEqual(Maybe<string>.EMPTY, optResult);
}
示例3: Map_null2_empty
public void Map_null2_empty()
{
//Arrange
Maybe<string> opt = new Maybe<string>("hello");
//Act
Maybe<string> optResult = opt //value = "hello"
.Map(str => str.Replace("o", "a")) //value = "hella"
.Map<string>(str => null) //value = null
.Map(str => str.Replace("l", "n")); //value = null
//Assert
Logger.Debug("result: " + optResult.Get());
Assert.AreEqual(Maybe<string>.EMPTY, optResult);
}