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 6784037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:56:30+00:00 2026-05-26T16:56:30+00:00

I am not sure if a constructor is exactly what I am looking for

  • 0

I am not sure if a constructor is exactly what I am looking for but if I explain what I am trying to do hopefully someone can tell me if I am trying to do is a silly idea or whether there are ways to do it.

So I have an enum:

public enum MessageType
{
    Normal, 
    Error, 
    Chat, 
    Groupchat, 
    Headline
}

This enum is basically a wrapper for the jabber.net MessageType. So I want to create my enum from this. So at the moment I have a function like this:

private MessageType ConvertMessageType(JabberMessageType jabberType)
{
    MessageType type = MessageType.Error;

    switch (jabberType)
    {
        case JabberMessageType.normal:
            type = MessageType.Normal;
            break;

        //etc
    }

    return type;
}

So I have to use enum MessageType type = ConvertMessageType(JabberMessageType.groupchat);

What I would like though is to be able to do something like:

enum MessageType type = MessageType(JabberMessageType.groupchat);
// or 
enum MessageType type = MessageType.FromJabberJid(JabberMessageType.groupchat);

So that the conversion belongs with the enum rather than being a method outtside of.

  • 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-26T16:56:31+00:00Added an answer on May 26, 2026 at 4:56 pm

    Why not create an extension method to do this for you?

    public static class ExtensionMethods
    {
        public static MessageType ConvertMessageType(this JabberMessageType jabberType)
        {
            switch(jabberType)
            {
                case JabberMessageType.normal:
                    return MessageType.Normal;
                // Add rest of types here.
                default:
                    return MessageType.Error;
            }
        }
    }
    

    Example usage:

    var type = JabberMessageType.normal; // JabberMessageType
    var messageType = type.ConvertMessageType(); // Converted to your custom MessageType
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not really sure how to word this exactly, so hopefully someone can make
I'm not sure exactly how to describe this question, but here goes. I've got
I'm not sure if/how I can check that the constructor actually exists before calling
Not sure if the title makes sense, but I am trying to return a
I have the following function/constructor/method (I'm not sure exactly what it is) List<T>& List<T>::operator=(const
Not sure if im just being stupid or something but here goes i work
Not sure how to ask this, but i'll give it a try: I have
Not sure if this is a big deal. But wondering why when the site
not sure what I'm missing here, but i keep getting the error. SQLSTATE[HY093]: Invalid
Not sure if this is the correct Stack Exchange website but here goes.. A

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.