将属性应用于返回值-在F#中 [英] Apply attribute to return value - In F#

查看:84
本文介绍了将属性应用于返回值-在F#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,可以将属性应用于方法的返回:

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

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

在F#中可能吗?

背景

我想要一种用F#编写的库的方法,该方法将以C#之类的语言来使用,以从方法返回动态 。如果我查看从C#编译的类似定义的方法,则似乎返回类型为object,并且DynamicAttribute应用于该对象的返回值。

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.

推荐答案

当然,您可以为返回值应用类似的属性目标。

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

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

此MSDN页面的末尾,请参阅有关如何指定属性目标的表 a>。

这篇关于将属性应用于返回值-在F#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆