F#没有价值的会员

时间:2014-07-31 19:57:52

标签: f#

我正在尝试将以下C#代码转换为F#:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
private class DOCINFOA
{
    [MarshalAs(UnmanagedType.LPStr)]
    public string nomeDocumento;
    [MarshalAs(UnmanagedType.LPStr)]
    public string arquivoSaida;
    [MarshalAs(UnmanagedType.LPStr)]
    public string tipoDado;
}

我正在做以下事情:

namespace Printer
    module RawPrinterHelper =
            [<StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)>]
            type DOCINFOA =
                [<MarshalAs(UnmanagedType.LPStr)>]
                member this.nomeDocumento
                [<MarshalAs(UnmanagedType.LPStr)>]
                member this.arquivoSaida
                [<MarshalAs(UnmanagedType.LPStr)>]
                member this.tipoDado

但我收到: A type definition requires one or more members。我可以让这些成员空着吗?

1 个答案:

答案 0 :(得分:4)

您可以使用val代替member

[<StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)>]
type DOCINFOA =
    [<MarshalAs(UnmanagedType.LPStr)>]
    val nomeDocumento : string
    [<MarshalAs(UnmanagedType.LPStr)>]
    val arquivoSaida : string
    [<MarshalAs(UnmanagedType.LPStr)>]
    val tipoDado : string