Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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#set属性_F# - Fatal编程技术网

派生类型的构造函数中的F#set属性

派生类型的构造函数中的F#set属性,f#,F#,我有一个从MVC类继承的类型。在我的构造函数(包含一个参数)中,我想设置Roles属性,但得到一个错误“这不是有效的对象构造表达式。显式对象构造函数必须调用备用构造函数,或者初始化对象的所有字段,并指定对超类构造函数的调用。”有人能帮我做错事吗 尝试#1: 类型MyAuthorizer= 继承授权属性 新([]角色:字符串[])= 设x=新的MyAuthorizer() //x、 角色语法有点混乱,但这应该是可行的。请注意then关键字,它允许您执行任意副作用,例如分配角色的值 type MyA

我有一个从MVC类继承的类型。在我的构造函数(包含一个参数)中,我想设置Roles属性,但得到一个错误“这不是有效的对象构造表达式。显式对象构造函数必须调用备用构造函数,或者初始化对象的所有字段,并指定对超类构造函数的调用。”有人能帮我做错事吗

尝试#1:

类型MyAuthorizer=
继承授权属性
新([]角色:字符串[])=
设x=新的MyAuthorizer()

//x、 角色语法有点混乱,但这应该是可行的。请注意
then
关键字,它允许您执行任意副作用,例如分配
角色的值

type MyAuthorizer =
    inherit AuthorizeAttribute

    new ([<ParamArray>] roles : string[]) as this = 
        { inherit AuthorizeAttribute() } then
            this.Roles <- ""
类型MyAuthorizer=
继承授权属性
新([]角色:字符串[]),因为此=
{inherit AuthorizeAttribute()}然后

this.Roles语法有点混乱,但这应该可以工作。请注意
then
关键字,它允许您执行任意副作用,例如分配
角色的值

type MyAuthorizer =
    inherit AuthorizeAttribute

    new ([<ParamArray>] roles : string[]) as this = 
        { inherit AuthorizeAttribute() } then
            this.Roles <- ""
类型MyAuthorizer=
继承授权属性
新([]角色:字符串[]),因为此=
{inherit AuthorizeAttribute()}然后

this.Roles尝试在对基构造函数的调用中包含属性及其值,如下所示:

type MyAuthorizer([<ParamArray>] roles : string[])    
    inherit AuthorizeAttribute(Roles = "")
键入MyAuthorizer([]角色:字符串[])
继承授权属性(角色=“”)

尝试在对基本构造函数的调用中包含属性及其值,如下所示:

type MyAuthorizer([<ParamArray>] roles : string[])    
    inherit AuthorizeAttribute(Roles = "")
键入MyAuthorizer([]角色:字符串[])
继承授权属性(角色=“”)

本质上是@MarkSeemann的副本,但情况不同。这里它必须调用基本构造函数。本质上是@MarkSeemann的一个副本,但情况不同。在这里,它必须调用基本构造函数。这似乎也可行!非常感谢。你能给我解释一下“然后”是什么意思吗?有一个解释。这似乎也有效!非常感谢。你能给我解释一下“然后”是什么意思吗?有一个解释,非常优雅。非常感谢。非常优雅。非常感谢。