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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:23:17+00:00 2026-06-09T10:23:17+00:00

Potentially an argumentative topic, but… I really hate that I can’t do the following:

  • 0

Potentially an argumentative topic, but… I really hate that I can’t do the following:

class User 
{
   public string ImageURL {get;set;}
}

class UserUI : User 
{
   public Brush ImageBrush {get;set;}
}

User user = GetFromUserFromServer(); //returns User type object, not UserUI
UserUI userUI = user;
userUI.ImageBrush = CreateBrush(userUI.ImageURL);

Instead, I use something like following:

class User 
{
   public virtual string ImageURL {get;set;}
}

class UserUI : User 
{
   public override string ImageURL 
    {
        get
        {
            return base.ImageURL ;
        }
        set
        {
            if (value != base.ImageURL )
            {                    
                base.ImageURL = value;
                ImageBrush = CreateBrush(value);
            }
        }
    }

   public Brush ImageBrush {get;set;}

   public UserUI(User user)
   {
       ImageURL = user.ImageURL;
   }
}

User user = GetFromServer();
UserUI userUI = new UserUI(user);

It’s a lot more verbose and any time I add fields to User, I need to make sure to copy them over in the UserUI constructor.

Is it fair to say that allowing down-casting would make all of this a lot easier and less error-prone?

  • 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-09T10:23:19+00:00Added an answer on June 9, 2026 at 10:23 am

    Err…no. What do you think should happen when you do this, after all, this is just as valid as your example:

    string whatever = "";
    UserUI userUI = whatever;
    userUI.ImageBrush = CreateBrush(userUI.ImageURL);
    

    After all, both inherit from object. Does userUI.ImageURL throw an exception since that property doesn’t exist? Or…what? This is madness. 🙂

    Edit: You say in a comment above:

    “Yeah. My argument is that there should maybe be a way of casting to a
    derived type, and the framework would automatically copy fields that
    exist in both types, and leave the others empty. In this case ImageURL
    would be copied.

    If that’s what you want, then use Automapper: https://github.com/AutoMapper/AutoMapper/wiki

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

Sidebar

Related Questions

I am writing an application that can potentially have hundreds of custom user controls
I have a datagrid that potentially can have many rows. As the user right
Potentially embarrassing question, but there is obviously something I'm missing that I want/need to
I have an application that can potentially have hundreds of memory mapped, i.e., mmap()
Potentially a topic for debate (or not) and I've searched and searched but not
What (potentially free) installer software can I use that integrates with Visual Studio, so
This has a potentially simple answer but I can't figure it out - double
Given a potentially huge integer value (in C# string format), I want to be
I have a table that potentially will have high number of inserts per second,
I have a Shape class containing potentially many vertices, and I was contemplating making

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.