I am using a using Microsoft.FSha开发者_开发问答rp.Core.Collections.FSharpMap and very often have to write:
var oo = world.Entity.TryFind(t);
var entity = oo == null ? null : oo.Value;
And similar. Any suggestions for a better style?
You could write an Extension Method:
public static T ValueOrDefault<T>(this FSharpOption<T> option)
{
return option == null ? default(T) : option.Value;
}
Usage:
var entity = world.Entity.TryFind(t).ValueOrDefault();
精彩评论