本文整理汇总了C#中Option.Unwrap方法的典型用法代码示例。如果您正苦于以下问题:C# Option.Unwrap方法的具体用法?C# Option.Unwrap怎么用?C# Option.Unwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option.Unwrap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OptionalTests
public void OptionalTests()
{
var a = new Option<string>();
Assert.IsFalse(a.IsSet);
Assert.Throws<UnexpectedObjectException>(() => a.Unwrap());
Assert.AreEqual("Oi", a.UnwrapOr("Oi"));
var b = new Option<string>("Hello, World!");
Assert.IsTrue(b.IsSet);
Assert.AreEqual("Hello, World!", b.Unwrap());
Assert.AreEqual("Hello, World!", b.UnwrapOr("Goodbye!"));
var c = new Option<int>(5);
Assert.AreEqual(42, c.Map((x) => new Option<int>(37 + x)).Unwrap());
var d = new Option<int>();
Assert.IsFalse(d.Map((x) => new Option<int>(x)).IsSet);
Assert.AreEqual(42, d.MapOr(42, (x) => x));
Assert.AreEqual(42, d.MapOrElse((x) => x, () => c.MapOr(0, (x) => 37 + x)));
Assert.IsFalse(a.And(b).IsSet);
Assert.IsTrue(b.And(c).IsSet);
Assert.AreEqual(5, b.And(c).Unwrap());
Assert.IsTrue(a.Or(b).IsSet);
Assert.AreEqual(b.Or(a), a.Or(b));
Assert.AreEqual(5, d.Or(c).Unwrap());
Assert.AreEqual(5, c.OrElse(() => new Option<int>(42)).Unwrap());
Assert.AreEqual(42, d.OrElse(() => new Option<int>(42)).Unwrap());
}
示例2: SpawnedObjectPool
/// Create an instance and provide a prefab factory to it to use
/// @param factory A wrapped gameobject, use Scene.Prefab()
/// @param limit The limit, if any, to the count of objects to spawn.
public SpawnedObjectPool(Option<GameObject> factory, int limit = -1)
{
if (factory)
{
_factory = factory.Unwrap();
_limit = limit >= 0 ? Option.Some(limit) : Option.None<int>();
return;
}
throw new Exception("Unable to create object pool from null prefab");
}