Click here to Skip to main content
       

C#

 
GeneralRe: How to create a colletion of properties in a C# class Pinmemberbnath0013-Jan-13 5:59 
GeneralRe: How to create a colletion of properties in a C# class PinmvpOriginalGriff3-Jan-13 8:24 
GeneralIf I use Dictionary, I am not able to serialize it Pinmemberbnath0013-Jan-13 9:08 
GeneralRe: If I use Dictionary, I am not able to serialize it PinmvpOriginalGriff3-Jan-13 9:50 
GeneralRe: If I use Dictionary, I am not able to serialize it Pinmemberbnath0013-Jan-13 10:44 
QuestionCA2214 Do not call overridable methods in constructors PinmentorDaveyM692-Jan-13 12:35 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmemberPIEBALDconsult2-Jan-13 13:38 
AnswerRe: CA2214 Do not call overridable methods in constructors PinmemberAlan N2-Jan-13 14:28 
This is one of those 'well it depends' rules. Think about the order in which chained constructors are called. The first thing derived class B's constructor does is call base class A's constructor.
 
If A's constructor now calls a virtual instance method defined in class B, it is accessing a partially initialised class. Remember that B's constructor has not run yet and all of B's instance data will be in an unknown state but it will be perfectly safe to call the instance method as long as it does not rely on instance data.
 
Examples of situations where this technique is used can be seen in the System.Windows.Forms class. Here you will find the protected bool ShowWithoutActivation property which is called internally and in the base class returns the constant value false. Overriding to return constant true changes the behaviour of a derived class. Similarly the property CreateParams can also be overridden to supply non default parameters to the base class.
 
So my feeling is it's OK to ignore CA2214 as long as you treat the overridden method or property as if it were static and don't do anything naughty.
 
Alan.
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM692-Jan-13 22:33 
GeneralRe: CA2214 Do not call overridable methods in constructors PinprotectorPete O'Hanlon2-Jan-13 22:53 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmemberBobJanova3-Jan-13 1:36 
GeneralRe: CA2214 Do not call overridable methods in constructors PinprotectorPete O'Hanlon3-Jan-13 1:42 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM693-Jan-13 3:22 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM693-Jan-13 12:10 
GeneralRe: CA2214 Do not call overridable methods in constructors Pinmemberjschell3-Jan-13 8:16 
GeneralRe: CA2214 Do not call overridable methods in constructors [modified] PinmentorDaveyM693-Jan-13 11:36 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmemberBernhard Hiller3-Jan-13 22:48 
GeneralRe: CA2214 Do not call overridable methods in constructors Pinmemberjschell4-Jan-13 13:08 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM695-Jan-13 3:00 
GeneralRe: CA2214 Do not call overridable methods in constructors Pinmemberjschell6-Jan-13 4:42 
AnswerRe: CA2214 Do not call overridable methods in constructors PinmemberBobJanova3-Jan-13 1:41 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM693-Jan-13 12:29 
QuestionBind listview row color to active index Pinmemberbornefalk2-Jan-13 9:50 
QuestionUI Automation and MMC PinmemberRonNYC22-Jan-13 5:57 
Questionmove a newfolder form a system on other system on the network by c# Pinmembera2bj1-Jan-13 23:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 15 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid