Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:40:53+00:00 2026-05-24T16:40:53+00:00

I have an enum with a DescriptionAttribute on each member. Since I’m not able

  • 0

I have an enum with a DescriptionAttribute on each member.
Since I’m not able to send this DescriptionAttribute over WCF (learned this the hard way), I have been trying to create a method that sends me a dictionary with descriptions.
After a bit of struggling around, I’ve come up with this method in my WCF-service:

public IDictionary<Enum, string> GetEnumDescriptionsList(string enumtype)
{
    Type t = Type.GetType(enumtype);
    if (t.BaseType != typeof(Enum))
    {
        return null;
    }

    var returnvalue = new Dictionary<Enum, string>();
    foreach (Enum value in Enum.GetValues(t))
    {
        returnvalue.Add(value, value.GetDescription());
    }
    return returnvalue;
}

The call to the method:

var myDict = GetEnumDescriptionsList(typeof (UserType).ToString());

This works fine when I make that call in the same class as the method, but when I make the call over WCF I got null returned.
After debugging I fnoticed that the string-parameter holds an “incorrect” value. I mean that UserType.ToString() on ther clientside has a different namespace then the one in the WCF-service.

Reading this post explained that issue.

At this moment I’m pretty stuck here: Generics are not possible, sending the type as a parameter of type Type is not possible (see this post),…
One last option is to write a method for each Enum I have (9 for the moment), but I got the feeling there’s a better way than that.

Thanks in advance.

UPDATE:
Using the solution provided by @KeithS I have following piece of code to create the dictionary:

Assembly asm = Assembly.GetExecutingAssembly();    
foreach (Type type in asm.GetTypes())
    {
        if (type.IsEnum)
        {
            enumTypeNames.Add(type.Name, type.AssemblyQualifiedName);
        }
    }

The method in the webservice returns a dict for every enummember for the given type:

public IDictionary<string, string> GetEnumDescriptionsList(string enumtypename)
{
    var enumtypenames = EnumMethods.GetEnumTypeNames();
    var returnvalue = new Dictionary<string, string>();

    string fullyQualifiedTypeName;
    enumtypenames.TryGetValue(enumtypename, out fullyQualifiedTypeName);

    var enumType = Type.GetType(fullyQualifiedTypeName);
    foreach (Enum value in Enum.GetValues(enumType))
    {
        returnvalue.Add(value.ToString(), value.GetDescription());
    }
    return returnvalue;
}

The call from the client:

var returnvalue = client.GetEnumDescriptionsList(typeof(UserType).Name);

Works like a charm, except for the issue I’ve posted a few days ago: Name of enum in innerclass changes through WCF-service

When I make a call from the client like:

var returnvalue = client.GetEnumDescriptionsList(typeof(ActionsMailDirectLinkContent).Name);

it gives the name “ActionsMailDirectLinkContent” back but in my dictionary of enumtypes I have “MailDirectLinkContent“.
So my question is if there’s a way to avoid this or do I have to take my enum(s) out of the Actions-class as only solution.

UPDATE 2:
As mentioned by @KeithS in his comment, I had to take the Enums out of my class. I have put them in a subfolder so they are still “grouped” but the methods above do work this way for all the Enums.

Thx Keith.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:40:53+00:00Added an answer on May 24, 2026 at 4:40 pm

    If you can safely assume that the namespace is not required to make an Enum type’s name unique (in other words there aren’t and will not be two Enums named “MyEnum” that you’re going to care about), you can set up a Dictionary<string,string> keyed to the “simple” (unqualified) Enum type name and containing the fully-qualified name of each Enum type on the server side. Then, you simply pass the simple Enum type name in to your method, and run it through the Dictionary to produce the “real” type name for which you get and return values, and any namespace differences between client and server won’t matter.

    The Dictionary could even be dynamically generated so it requires less maintenance, but you could start running into problems with scanning assemblies for Enum types (it would help if there was only one assembly or namespace that had all the Enums you care about).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an enum construct like this: public enum EnumDisplayStatus { None = 1,
I have this enum: enum ButtonState { BUTTON_NORMAL = 0, BUTTON_PRESSED = 1, BUTTON_CLICKED
I have this enum: [Flags] public enum ExportFormat { None = 0, Csv =
Well the problem is that I have this enum, BUT I don't want the
I have an enum with Description attributes like this: public enum MyEnum { Name1
DescriptionAttribute not allow to be set multiple times. Is there any way to have
I have enum ClientType{INTERNAL,ADMIN}, i am able to persist enum with hibernate annotations. but
I have an enum in my objective-C code similar to this: typedef enum {
I have an enum, that looks like this: enum Suit {Clubs, Diamonds, Hearts, Spades};
I have an enum that looks a little bit like this: public enum Numbers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.