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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:03:55+00:00 2026-06-15T14:03:55+00:00

So, I have a base object called LogEvent and I create other classes derived

  • 0

So, I have a base object called LogEvent and I create other classes derived from that such as an ExecuteEvent or a SubmitEvent. When I try to get the type of the specific instances they always come back as LogEvent. Here’s each of the classes’ definitions:

class LogEvent
    {
        public List<LogEventAttribute> eventAttributes = new List<LogEventAttribute>();
        public int clusterId;
        public DateTime eventTime;

        public LogEvent(List<LogEventAttribute> eventAttributes)
        {
            this.eventAttributes = eventAttributes;
            this.clusterId = Convert.ToInt32(eventAttributes.Find(p => p.name.Equals("Cluster")).value);
            this.eventTime = DateTime.Parse(eventAttributes.Find(p => p.name.Equals("EventTime")).value);

        }
    }

    class SubmitEvent : LogEvent
    {
        public string submitHost;

        public SubmitEvent(List<LogEventAttribute> eventAttributes)
            : base(eventAttributes)
        {
            this.submitHost = eventAttributes.Find(p => p.name.Equals("SubmitHost")).value;
        }
    }

    class ExecuteEvent : LogEvent
    {
        public string executeHost;

        public ExecuteEvent(List<LogEventAttribute> eventAttributes)
            : base(eventAttributes)
        {
            this.executeHost = eventAttributes.Find(p => p.name.Equals("ExecuteHost")).value;
        }
    }

    class TerminatedEvent : LogEvent
    {
        public bool successful;

        public TerminatedEvent(List<LogEventAttribute> eventAttributes)
            : base(eventAttributes)
        {
            this.successful = Convert.ToBoolean(eventAttributes.Find(p => p.name.Equals("TerminatedNormally")).value);
        }
    }

    class LogEventAttribute
    {
        public string name, type, value;
        public LogEventAttribute(string name, string type, string value)
        {
            this.name = name;
            this.type = type;
            this.value = value;
        }
    }

And here’s where I try to do different things based on the type of class:

switch (currentEvent.GetType().ToString())
                    {
                        case "ExecuteEvent":
                            ExecuteEvent currentExEvent = currentEvent as ExecuteEvent;
                            item.SubItems.Add("Job executed by " + currentExEvent.executeHost);
                            break;
                        case "SubmitEvent":
                            SubmitEvent currentSubEvent = currentEvent as SubmitEvent;
                            item.SubItems.Add("Job submitted by " + currentSubEvent.submitHost);
                            break;
                    }

The switch always gets passed over because currentEvent.GetType().ToString() always comes out to LogEvent.

Edit: The problem was that I was first creating these different classes differently. Here’s the faulty code:

LogEventAttribute eventTypeAttribute = currentEventAttributes.Find(p => p.name.Equals("MyType"));
                string eventType = eventTypeAttribute.type;
switch (eventType)
                {
                    case "SubmitEvent":
                        logEvents.Add(new SubmitEvent(currentEventAttributes));
                        break;
                    case "ExecuteEvent":
                        logEvents.Add(new ExecuteEvent(currentEventAttributes));
                        break;
                    case "TerminatedEvent":
                        logEvents.Add(new TerminatedEvent(currentEventAttributes));
                        break;
                    default:
                        logEvents.Add(new LogEvent(currentEventAttributes));
                        break;
                }

On the second line where I’m getting the property “type” from the eventTypeAttribute, I should instead be getting the value property. I was using the type property to determine the type of the value the attribute has stored in its value property. Argh, TGIF.

  • 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-06-15T14:03:56+00:00Added an answer on June 15, 2026 at 2:03 pm

    If you actually get type object for LogEvent from GetType, then you have instances of the LogType class, not of any of the derived classes. However, I don’t think that you get what you think that you get.

    Using ToString() on the Type object will return the complete namespace, e.g. "MyApp.ExecuteEvent" rather than "ExecuteEvent".

    Use the Name property instead:

    switch (currentEvent.GetType().Name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Object base class, and I have several derived classes called Item,
I have a base class called Mijloc_transport and 2 derived classes called Masina and
I have a base class called Object. PhysicsObject inherits from Object. Ball inherits from
I have a base class A and classes B and C are derived from
I have a Base Class, called primitive Graphics. derived from this class are several
I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC
I have a Sinatra::Base object that I would like to include in all of
I have a base class pointer pointing to a derived class object. I am
I have a simple base entity type called EntityBase that implements IEquatable<EntityBase>. I've used
I have a stateless, abstract base class from which various concrete classes inherit. Some

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.