Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get enum as parameter thru interface

How to get enum as parameter thru interface

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studiohelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MichCl
    wrote on last edited by
    #1

    I have an enum definition that I wanted to put in my interface, but I'm getting a compilation error: Mode: interfaces cannot declare types

    public enum Mode
    {
    Off = 0,
    On1 = 1,
    On2 = 2
    }

    and the interface has a method in it that classes implementing it must define, where I want to pass the mode as a param:

    int ProcessTWrit(ref Byte[] wDat, ref Byte[] sDat, ref Byte[] dataCk, int theMode);

    So, I had to put separate definitions of the enum in both my El.cs and the class that it's calling through the interface. I have my El.cs that I have also defined the enum above and want to call the above method:

    result = cr.ProcessTWrit(ref wDat, ref sDat, ref dataCk, (int)Mode.On1);

    My question is, is there a way that I can put my Mode enum in the interface so that the calling class and the receiving class can pass/use the enum values, so I don't have to have multiple definitions of the enum? There doesn't seem to be any other class that it would make sense for me to put the Mode definition in. This is a factory implementation. It looks like this: El.cs =======> iCR.cs ==========================> CR5.cs ..........calls................ ProcessTWrit()................................................................ ProcessTWrit(){} with multiple definitions of Mode in El.cs and CR5.cs. The three classes discussed above are in separate Visual Studio projects, if it makes a difference.

    D P 2 Replies Last reply
    0
    • M MichCl

      I have an enum definition that I wanted to put in my interface, but I'm getting a compilation error: Mode: interfaces cannot declare types

      public enum Mode
      {
      Off = 0,
      On1 = 1,
      On2 = 2
      }

      and the interface has a method in it that classes implementing it must define, where I want to pass the mode as a param:

      int ProcessTWrit(ref Byte[] wDat, ref Byte[] sDat, ref Byte[] dataCk, int theMode);

      So, I had to put separate definitions of the enum in both my El.cs and the class that it's calling through the interface. I have my El.cs that I have also defined the enum above and want to call the above method:

      result = cr.ProcessTWrit(ref wDat, ref sDat, ref dataCk, (int)Mode.On1);

      My question is, is there a way that I can put my Mode enum in the interface so that the calling class and the receiving class can pass/use the enum values, so I don't have to have multiple definitions of the enum? There doesn't seem to be any other class that it would make sense for me to put the Mode definition in. This is a factory implementation. It looks like this: El.cs =======> iCR.cs ==========================> CR5.cs ..........calls................ ProcessTWrit()................................................................ ProcessTWrit(){} with multiple definitions of Mode in El.cs and CR5.cs. The three classes discussed above are in separate Visual Studio projects, if it makes a difference.

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      If the existing projects don't reference each other then the only other way is to create another common project (dll class library), put any common objects in there and reference the new project (after building) in the existing ones

      Dave
      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      1 Reply Last reply
      0
      • M MichCl

        I have an enum definition that I wanted to put in my interface, but I'm getting a compilation error: Mode: interfaces cannot declare types

        public enum Mode
        {
        Off = 0,
        On1 = 1,
        On2 = 2
        }

        and the interface has a method in it that classes implementing it must define, where I want to pass the mode as a param:

        int ProcessTWrit(ref Byte[] wDat, ref Byte[] sDat, ref Byte[] dataCk, int theMode);

        So, I had to put separate definitions of the enum in both my El.cs and the class that it's calling through the interface. I have my El.cs that I have also defined the enum above and want to call the above method:

        result = cr.ProcessTWrit(ref wDat, ref sDat, ref dataCk, (int)Mode.On1);

        My question is, is there a way that I can put my Mode enum in the interface so that the calling class and the receiving class can pass/use the enum values, so I don't have to have multiple definitions of the enum? There doesn't seem to be any other class that it would make sense for me to put the Mode definition in. This is a factory implementation. It looks like this: El.cs =======> iCR.cs ==========================> CR5.cs ..........calls................ ProcessTWrit()................................................................ ProcessTWrit(){} with multiple definitions of Mode in El.cs and CR5.cs. The three classes discussed above are in separate Visual Studio projects, if it makes a difference.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        MichCl wrote:

        class ... to put the Mode definition in

        An enumeration is a type and doesn't need to be in a class. You could put the enumeration and interface definition in their own project/DLL and reference it from the others, but generally a DLL should hold more than just those two things.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups