如何设置包含枚举的对象的多个参数的值?

How do you set the value of more than 1 parameter of an object containing enums?

我在 VB.NET 中使用 Protobuf-net 将电机命令从一台计算机传递到另一台计算机。下面是我的原型文件的示例,其中包含两个枚举,CommandActionMotorChoice。我想在一台计算机上为它们中的每一个设置一个值,并从另一台计算机上检索这些值。

Public Class RemoteControl

<ProtoContract>
Public Class Command

    <ProtoContract>
    Enum CommandAction
        <ProtoMember(1)>
        HOME_MOTOR
        <ProtoMember(2)>
        MOVE_ABS
    End Enum

    <ProtoContract>
    Enum MotorChoice
        <ProtoMember(1)>
         MOTOR1
        <ProtoMember(2)>
         MOTOR2
    End Enum
End Class
End Class

我 运行 遇到了尝试为动作和电机选择设置值的问题。当我只需要设置一个参数时,下面的语句就起作用了

Dim myProto As New RemoteControl.Command.CommandAction
myProto= RemoteControl.Command.CommandAction.HOME_MOTOR

尝试设置两个参数时,我尝试了以下操作:

 Dim myProtoExpanded As New RemoteControl.Command
 myProtoExpanded.CommandAction = RemoteControl.Command.CommandAction.HOME_MOTOR
 myProtoExpanded.MotorChoice= RemoteControl.Command.MotorChoice.MOTOR1

编译器抛出错误,说左边两边都是类型,不能用作表达式。 myProtoExpanded 的两个参数在序列化前的正确设置方法是什么?我想发送一个包含两个枚举信息的对象

您定义了 Enum 数据类型,但没有将该枚举的数据成员添加到命令中 class。

Public Class Command
   Enum CommandAction
      ... 
   End Enum
   Enum MotorChoice
        ....
   End Enum

   Public action as CommandAction
   Public motor as MotorChoice

End Class

myProtoExpanded.action = RemoteControl.Command.CommandAction.HOME_MOTOR
myProtoExpanded.motor = RemoteControl.Command.MotorChoice.MOTOR1