Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F#:如何将Json.NET[JsonConstructor]属性应用于主构造函数?_Json_F#_Json.net - Fatal编程技术网

F#:如何将Json.NET[JsonConstructor]属性应用于主构造函数?

F#:如何将Json.NET[JsonConstructor]属性应用于主构造函数?,json,f#,json.net,Json,F#,Json.net,我试图在F#中做一些事情,比如jsonstructuratribute中的示例: 公共类用户 { 公共字符串用户名{get;private set;} 启用公共布尔的{get;private set;} 公共用户() { } [JsonConstructor] 公共用户(字符串用户名,启用bool) { 用户名=用户名; 启用=启用; } } F#中的模拟似乎类似于以下内容,但我在[]的位置上遇到了一个错误: []//错误!(见下文) 键入用户(用户名:字符串,已启用:bool)= membe

我试图在F#中做一些事情,比如
jsonstructuratribute
中的示例:

公共类用户
{
公共字符串用户名{get;private set;}
启用公共布尔的{get;private set;}
公共用户()
{
}
[JsonConstructor]
公共用户(字符串用户名,启用bool)
{
用户名=用户名;
启用=启用;
}
}
F#中的模拟似乎类似于以下内容,但我在
[]
的位置上遇到了一个错误:

[]//错误!(见下文)
键入用户(用户名:字符串,已启用:bool)=
member this.UserName=用户名
成员this.Enabled=Enabled
错误是

此属性在此语言元素上使用无效


那么,如何用
[]
装饰主构造函数呢?

事实证明,这非常简单。将
[]
放在主构造函数的参数列表之前,以主构造函数为目标:

键入用户[](用户名:字符串,已启用:bool)=
member this.UserName=用户名
成员this.Enabled=Enabled