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. Including an additional enum property into an object?

Including an additional enum property into an object?

Scheduled Pinned Locked Moved C#
questioncsharplinq
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.
  • G Offline
    G Offline
    Goalie35
    wrote on last edited by
    #1

    How can I assign an additional "enum" property to a pre-existing object? I'm building a Trophy system for my website where user's can earn trophies for various achievements. I currently have a "Trophy" object which was created for me automatically in Linq when I created my dbml file. Nice and simple so far :) Now however, I want to include an additional property to my "Trophy" object of type enum called "TrophyLevel". For several, long winded reasons, I don't want to include TrophyLevel as a part of the actual "Trophy" object. So, I've tried setting it up in a partial class like the following:

    public partial class Trophy
    {
    public enum TrophyLevel
    {
    Bronze = 1,
    Silver = 2,
    Gold = 3,
    Platinum = 4
    }
    }

    Is this the correct way I should be setting this up, and if so, how do I access it? So, basically, I want to be able to have code like the following: Trophy.TrophyLevel = 1; OR String level = Trophy.TrophyLevel; Am I going about this correctly? Thanks

    N B 2 Replies Last reply
    0
    • G Goalie35

      How can I assign an additional "enum" property to a pre-existing object? I'm building a Trophy system for my website where user's can earn trophies for various achievements. I currently have a "Trophy" object which was created for me automatically in Linq when I created my dbml file. Nice and simple so far :) Now however, I want to include an additional property to my "Trophy" object of type enum called "TrophyLevel". For several, long winded reasons, I don't want to include TrophyLevel as a part of the actual "Trophy" object. So, I've tried setting it up in a partial class like the following:

      public partial class Trophy
      {
      public enum TrophyLevel
      {
      Bronze = 1,
      Silver = 2,
      Gold = 3,
      Platinum = 4
      }
      }

      Is this the correct way I should be setting this up, and if so, how do I access it? So, basically, I want to be able to have code like the following: Trophy.TrophyLevel = 1; OR String level = Trophy.TrophyLevel; Am I going about this correctly? Thanks

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Yes, this is correct. EF generated a partial class for Trophy which you would extend by adding another partial class definition in the same namespace. http://msdn.microsoft.com/en-us/library/wa80x488(v=VS.100).aspx[^]


      No comment

      1 Reply Last reply
      0
      • G Goalie35

        How can I assign an additional "enum" property to a pre-existing object? I'm building a Trophy system for my website where user's can earn trophies for various achievements. I currently have a "Trophy" object which was created for me automatically in Linq when I created my dbml file. Nice and simple so far :) Now however, I want to include an additional property to my "Trophy" object of type enum called "TrophyLevel". For several, long winded reasons, I don't want to include TrophyLevel as a part of the actual "Trophy" object. So, I've tried setting it up in a partial class like the following:

        public partial class Trophy
        {
        public enum TrophyLevel
        {
        Bronze = 1,
        Silver = 2,
        Gold = 3,
        Platinum = 4
        }
        }

        Is this the correct way I should be setting this up, and if so, how do I access it? So, basically, I want to be able to have code like the following: Trophy.TrophyLevel = 1; OR String level = Trophy.TrophyLevel; Am I going about this correctly? Thanks

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

        Yes, you are certainly creating a valid extension to the Trophy class via using the 'partial keyword, and I assume you realize that both the original and added classes should/must be declared with the partial keyword:

        public partial class Trophy

        If I assume, based on what you present here, that 'Trophy is not a static class, then you are going to be creating instances of Trophy: you'll be using the instances like this:

        Trophy tp1 = new Trophy();
        Trophy tp2 = new Trophy();

        tp1.theTrophyLevel = Trophy.TrophyLevel.Platinum;
        tp2.theTrophyLevel = Trophy.TrophyLevel.Silver;

        String level = tp1.theTrophyLevel.ToString();

        "Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill

        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