PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, June 25, 2022

[FIXED] How to prevent hide or override on a public property

 June 25, 2022     c#, compiler-errors, inheritance, oop     No comments   

Issue

I have an abstract base class that has a Property on it that I would like to prevent both hiding, aka new, and override on.

public abstract class DomainObject
{
    public bool IsDeleted { get; set; }
}

public class BankAccount : DomainObject
{
    public bool IsDeleted { get; set; }
}

The issue is: I need BankAccount to inherit from the base DomainObject class, so I can't mark it as sealed, but I want to prevent the situation, an override or new, of IsDeleted at compile time.


Solution

I've had this same need for the same reason that you mentioned in comments: preventing issues caused by generated code. My solution was to make this specific warning an error, which can be done by adding "0108" to the "Project Properties" => "Build" => "Treat warnings as errors" => "Specific warnings" list.

I'd be curious to know why this was considered to be only a warning and not an error in the first place. Surely, it is some "brittle base class" situation that I haven't considered...



Answered By - MarkPflug
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing