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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:12:04+00:00 2026-05-28T07:12:04+00:00

I have a base class called Base . This base class has a method

  • 0

I have a base class called Base. This base class has a method defined as:

protected virtual string GetFormattedAttribute(string propertyName, object propertyValue)

The propertyValue is defined as:

dynamic propertyValue

So different type of values are assigned to it and appropriate methods are called automatically. For example, I have another virtual method in the same base class for DateTime as:

protected virtual string GetFormattedAttribute(string propertyName, DateTime propertyValue)

This works perfectly. Now, I have a dervied class in which I define the same method, which accepts a List<Contact>:

protected string GetFormattedAttribute(string propertyName, List<Contact> contacts)

This, however, is never called and the first method with propertyValue as object in Base is called instead (I’m calling this method with a derived class object). I tried new and override keywords in the derived class method, but that doesn’t work. Any ideas how can I achieve this result?

  • 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-28T07:12:04+00:00Added an answer on May 28, 2026 at 7:12 am

    This has nothing to do with an override. You are creating an overload of GetFormattedAttribute. If you call GetFormattedAttribute on a variable of type Base it doesn’t know about the overload in the derived class, even if the instance in fact is of the derived type.

    To put it simply: Your overload in the derived class will only be called, of it is being called on a variable of the derived class or a class that derives from it. Because the method is protected, I assume that you call GetFormattedAttribute somewhere in your base class. In that scenario, it is impossible for you to use the overloaded GetFormattedAttribute in the derived class.

    One way to achieve the result you are looking for would be something like this:

    1. override the version with the object parameter in your derived class
    2. put a type check in that overriden version. If the type is List<Contact> call that overload, otherwise call the base implementation

    Something like this:

    class Derived : Base
    {
        protected override string GetFormattedAttribute(string propertyName,
                                                        object propertyValue)
        {
            var list = propertyValue as List<Contact>;
            if(list == null)
                return base.GetFormattedAttribute(propertyName, propertyValue);
            else
                return GetFormattedAttribute(propertyName, list);
        }
    
        protected string GetFormattedAttribute(string propertyName,
                                               List<Contact> contacts)
        {
            // ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Object Factory Class which has a method called registerCreator as defined
I have a base class with a property called Name, which has an XmlText
I have a base class that has a method that creates an instance of
I have a base class that has a method that gets executed by derived
I have a base class called Component. I also have 2 interfaces I2DComponent, and
I have an abstract base class called Shape from which both Circle and Rectangle
Ok so I have an abstract base class called Product, a KitItem class that
I have a class Contact (base class),a class called Customer and a class called
I have a table called Users ( class User < ActiveRecord::Base ) and a
I have a base class object array into which I have typecasted many different

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.