C# to F# Convert public partial class Device : MarshalByRefObject

╄→гoц情女王★ 提交于 2019-12-30 21:59:45

问题


public partial class Device : MarshalByRefObject
{
    internal bool FindTagName(string name, OneTag tag)
    {
        foreach (FuncSect fs in listFuncSect)
        {
            foreach (OneTag ot in fs.listTags)
            {
                if (ot != tag && ot.Name == name) return true;
            }
        }
        return false;
    }

still have no idea how to convert this "partial" and "internal" to F#

thank you


回答1:


As leppie says, there's no direct support for partial, although you could achieve a similar effect with intrinsic type extensions. F# does support internal methods, so your example would look like:

// primary definition somewhere
type Device() =
  inherit MarshalByRefObject()
  ...


// type extension (roughly equivalent to partial class)
type Device with
  member internal this.FindTagName(name:string, tag:OneTag) =
    listFuncSect
    |> Seq.exists 
         (fun fs -> 
            fs.listTags 
            |> Seq.exists (fun ot -> ot <> tag && ot.name = name))



回答2:


partial is a C# compiler feature, it ain't gonna work on F#, you will have to combined all the partial classes, or inherit from an existing one.



来源:https://stackoverflow.com/questions/4376275/c-sharp-to-f-convert-public-partial-class-device-marshalbyrefobject

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