f#のプロパティに複数の列挙値を割り当てるための構文は何ですか?

StackOverflow https://stackoverflow.com//questions/10655679

  •  11-12-2019
  •  | 
  •  

質問

F#にServiceStack WebServiceを書き、いくつかの機能を制限する必要があります(たとえば、SOAPサポートの削除)。

C#では、Pipe Operationを使用して、enableFeaturesプロパティに複数の列挙型(Servicestack.ServiceHost.Feature)を割り当てています。

SetConfig(new EndpointHostConfig
{
    DebugMode = true, //Show StackTraces in responses in development
    EnableFeatures = Feature.Json | Feature.Xml | Feature.Html | Feature.Metadata | Feature.Jsv
});
.

しかし、F#でこれを達成するためにパイプを使うことはできません、そして私が試みるすべてのものは、enumsへの関数アプリケーションを実行しようとしています。この場合は複数の列挙型の割り当てについてどうすればよいですか?

役に立ちましたか?

解決

トリプルパイプを使う:

EnableFeatures = Feature.Json ||| Feature.Xml ||| Feature.Html ||| Feature.Metadata ||| Feature.Jsv
.

他のヒント

束を持っている場合は、reduceを使用していくつかのキーストロークを保存できます。

List.reduce (|||) [Feature.Json; Feature.Xml; Feature.Html; Feature.Metadata]
.

基礎となる値の構築に基づいて値を作成します。

EnabledFeatures = enum<Feature>(16); // or whatever the full flag value would be for Json + Xml + Html + Metadata, etc
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top