需要帮助将带有泛型的接口从C转换为F#吗#
我有这个C代码需要帮助将带有泛型的接口从C转换为F#吗#,f#,F#,我有这个C代码 公共接口存储库:IRepository { IQueryable FindByLocation(浮动纬度、浮动经度); IQueryable FindUpcomingDinners(); IQueryable FindInnerSbyText(字符串q); 无效删除RSVP(RSVP RSVP); } 及 公共接口IRepository { IQueryable所有{get;} 可计量的所有包括(参数表达式[]包括属性); T Find(int-id); 无效插入更新(T晚餐)
公共接口存储库:IRepository
{
IQueryable FindByLocation(浮动纬度、浮动经度);
IQueryable FindUpcomingDinners();
IQueryable FindInnerSbyText(字符串q);
无效删除RSVP(RSVP RSVP);
}
及
公共接口IRepository
{
IQueryable所有{get;}
可计量的所有包括(参数表达式[]包括属性);
T Find(int-id);
无效插入更新(T晚餐);
无效删除(int-id);
无效提交更改();
}
我想翻译成F。如何创建泛型接口?就我所知,MSDN中的F#接口示例并没有真正的等价物。好的,我应该先用谷歌搜索“F#接口与泛型”
type public-IRepository定义通用接口实际上有两种方法,但几乎所有F#代码都使用您在现有答案中提到的样式。另一个选项仅用于某些标准F#类型,如'T option
和'T list
:
type IRepository<'T> = // The standard way of doing things
type 'T IRepository = // Used rarely for some standard F# types
类型IRepository
//使用“params”属性注释参数并指定参数名称
摘要包括
:[]IncludeProperty:表达式
类型库=
//从另一个接口继承
继承假定
//并添加一组其他成员(这里我没有指定参数名称)
摘要:FindComingDinners:unit->IQueryable
抽象FindInnerSbyText:string->IQueryable
未来参考?你救了我几个小时!谢谢
type IRepository<'T> = // The standard way of doing things
type 'T IRepository = // Used rarely for some standard F# types
// We inherit from this type later, so I moved it to an earlier location in the file
type IRepository<'T> =
// Read-only properties are easier to define in F#
abstract All : IQueryable<'T>
// Annotating parameter with the 'params' attribute and also specifying param name
abstract AllIncluding
: [<ParamArray>] includeProperties:Expression<Func<'T, obj>>[] -> IQueryable<'T>
type IDinnerRepository =
// Inherit from another interface
inherit IRepository<Dinner>
// And add a bunch of other members (here I did not specify parameter names)
abstract FindUpcomingDinners : unit -> IQueryable<Dinner>
abstract FindDinnersByText : string -> IQueryable<Dinner>