Apply attribute to return value - In F#

为君一笑 提交于 2019-12-10 12:57:53

问题


in C# it is possible to apply an attribute to the return of a method:

[return: DynamicAttribute]
public object Xyz() {
  return new ExpandoObject();
}

Is this possible in F#?

Background:

I would like a method of a library written in F# which will be consumed in a language like C# to return "dynamic" from a method. If I look into a similarly defined method compiled from C# it seems like the return type is object and the DynamicAttribute is applied to the return value of the object.


回答1:


Sure, you can apply a similar attribute target for the return value.

let SomeFunc x : [<return: SomeAttribute>] SomeType =
    SomeOperation x

See the table of how to specify attribute targets at the end of this MSDN page.



来源:https://stackoverflow.com/questions/8467227/apply-attribute-to-return-value-in-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!