の代わりにnullを返します。F#
.net 4.6.1
VS2015
に開発しました。F#メソッドは、オプション
type CommonHelper =
static member SideEffectOnNull act x = if x = null then act(); x else x
static member SideEffectOnNotNull act x = if x <> null then act(); x else x
...
static member GetPerformanceCounter (fname: CounterFullName) =
let getCounterInternal (counterFullName: CounterFullName) =
Log.Information("Getting counter: {category}\\{name}\\{instance} ", counterFullName.Category, counterFullName.Name, counterFullName.Instance)
let receivedCategory = PerformanceCounterCategory.GetCategories().FirstOrDefault(fun x -> String.Equals(x.CategoryName, counterFullName.Category.Category, StringComparison.InvariantCultureIgnoreCase))
if receivedCategory = null then
Serilog.Log.Warning ("Category not found: {category}", counterFullName.Category); null
else
let receivedCounters = PerforrmanceCounterProxy.GetPerformanceCountersFromCategoryOrNull counterFullName.Instance receivedCategory
if receivedCounters = null then
Log.Warning ("Instance not found {name}(instance: {instance}) in category {category}", counterFullName.Name, counterFullName.Instance, counterFullName.Category); null
else
receivedCounters.FirstOrDefault(fun y -> String.Equals(y.CounterName, counterFullName.Name.Name, StringComparison.InvariantCultureIgnoreCase))
|> CommonHelper.SideEffectOnNull (fun unit -> Log.Warning ("Name {name}(instance: {instance}) not found for category {category}", counterFullName.Name, counterFullName.Instance, counterFullName.Category))
getCounterInternal fname
|> CommonHelper.SideEffectOnNull (fun unit ->Log.Warning("Getting counter failed: {category}\\{name}\\{instance}", fname.Category, fname.Name, fname.Instance))
|> CommonHelper.SideEffectOnNotNull (fun unit ->Log.Information("Getting Counter secceed: {category}\\{name}\\{instance}", fname.Category, fname.Name, fname.Instance))
|> (fun x -> if x = null then None else Option.Some(x))
しかし、私はnull
代わりのoption
を受け、このメソッドを呼び出す:私はメソッドを持っています。 私は間違っていますか?
私の推測 - 'visual studio 2015'に関連した問題。ビジネスロジックがうまくいくので、私は 'VS2015' UIが間違った情報を表示すると思います – burzhuy
値型の場合は' default(T) '、参照型の場合は' null'を使って、その型のデフォルト値を表示しました。 – Asti