locked
Using enums in service State? RRS feed

  • Question

  • I am trying to use a simple enum as a DataMember in the State of a service, but when I try to compile the proxy build fails.

     

    The enum is as follows:

    public enum MoveStates

    {

    Stop,

    Turn,

    MoveStraight

    }

     

    Then I add it to the state as follows:

    [DataMember]

    public MoveStates MoveState;

     

    The compilation error is:

    Error 1 The type or namespace name 'MoveStates' could not be found (are you missing a using directive or an assembly reference?) C:\Microsoft Robotics Studio (1.5)\samples\Intro\Robotics.Intro.Proxy.IntroTypes.cs 93 17 Intro

     

    Is there some trick to doing this, or is it simply not possible because enums cannot be serialized into the saved state?

     

    Trevor

     

    P.S. I have a workaround which is as follows, but I don't like it:

    private int _moveState = (int) MoveStates.Stop;

    [DataMember]

    public int MoveState

    {

    get { return _moveState; }

    set { _moveState = (int)value; }

    }

    Thursday, July 12, 2007 7:16 AM

Answers

  • Hi Trevor,

    You have to label the enum with [DataContract].

    -Ben
    Thursday, July 12, 2007 1:33 PM

All replies

  • Hi Trevor,

    You have to label the enum with [DataContract].

    -Ben
    Thursday, July 12, 2007 1:33 PM
  • Doh!

     

    Thanks Ben :-)

     

    Trevor

    Saturday, July 14, 2007 7:08 AM