Click here to Skip to main content
       

C#

 
GeneralRe: KeyValuePair from reference dll PinmemberIsaksson4-Jan-13 1:41 
Questionhow to connect and disconnect to internet by Exist connection Pinmemberapadana_19892-Jan-13 18:44 
QuestionRe: how to connect and disconnect to internet by Exist connection PinmvpRichard MacCutchan2-Jan-13 23:15 
AnswerRe: how to connect and disconnect to internet by Exist connection Pinmemberjschell3-Jan-13 9:11 
QuestionHow to create a colletion of properties in a C# class Pinmemberbnath0012-Jan-13 13:59 
AnswerRe: How to create a colletion of properties in a C# class PinmemberPIEBALDconsult2-Jan-13 14:34 
AnswerRe: How to create a colletion of properties in a C# class PinmvpAbhinav S2-Jan-13 16:42 
AnswerRe: How to create a colletion of properties in a C# class PinmvpOriginalGriff2-Jan-13 22:16 
GeneralRe: How to create a colletion of properties in a C# class Pinmemberbnath0013-Jan-13 6:59 
GeneralRe: How to create a colletion of properties in a C# class PinmvpOriginalGriff3-Jan-13 9:24 
GeneralIf I use Dictionary, I am not able to serialize it Pinmemberbnath0013-Jan-13 10:08 
GeneralRe: If I use Dictionary, I am not able to serialize it PinmvpOriginalGriff3-Jan-13 10:50 
GeneralRe: If I use Dictionary, I am not able to serialize it Pinmemberbnath0013-Jan-13 11:44 
QuestionCA2214 Do not call overridable methods in constructors PinmentorDaveyM692-Jan-13 13:35 
Maybe I just need sleep to recover from recent festivities - but I can't think of a way to fix this code to comply with the FX Cop warning.
The only thing that comes to mind is to create protected setters (or setter methods) in the base class and call those from the derived constructors...
public abstract class BaseClass
{
    private int id;
        
    // CA2214 Do not call overridable methods in constructors
    protected BaseClass()
    {
        Initialize(out id); // Initialize derived class with it's own specific data and get common data back here for initialization
    }
 
    public int Id { get { return id; } }
 
    protected abstract void Initialize(out int id);
}
public class ConcreteA : BaseClass
{
    public ConcreteA()
        : base()
    { }
 
    protected override void Initialize(out int id)
    {
        ConcreteAIntializationData data = NativeMethods.ConcreteAInitialize();
        id = data.Id;
    }
}
public class ConcreteB : BaseClass
{
    private string name;
 
    public ConcreteB()
        : base()
    { }
 
    protected override void Initialize(out int id)
    {
        ConcreteBIntializationData data = NativeMethods.ConcreteBInitialize();
        id = data.Id;
        name = data.name;
    }
}
 
public static class NativeMethods
{
    // In the real code this is an external C++ dll call
    public static ConcreteAIntializationData ConcreteAInitialize()
    {
        return new ConcreteAIntializationData();
    }
    // In the real code this is an external C++ dll call
    public static ConcreteBIntializationData ConcreteBInitialize()
    {
        return new ConcreteBIntializationData();
    }
}
// In the real code this is a C++ structure
public class ConcreteAIntializationData
{
    private int id;
 
    // In the real code this struct is filled by unmanaged code.
    public ConcreteAIntializationData()
    {
        id = 1;
    }
 
    public int Id
    {
        get { return id; }
    }
}
public class ConcreteBIntializationData
{
    private int id;
    public string name;
 
    // In the real code this struct is filled by unmanaged code.
    public ConcreteBIntializationData()
    {
        id = 2;
        name = "Name";
    }
 
    public int Id
    {
        get { return id; }
    }
    public string Name
    {
        get { return name; }
    }
}
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



GeneralRe: CA2214 Do not call overridable methods in constructors PinmemberPIEBALDconsult2-Jan-13 14:38 
AnswerRe: CA2214 Do not call overridable methods in constructors PinmemberAlan N2-Jan-13 15:28 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM692-Jan-13 23:33 
GeneralRe: CA2214 Do not call overridable methods in constructors PinprotectorPete O'Hanlon2-Jan-13 23:53 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmemberBobJanova3-Jan-13 2:36 
GeneralRe: CA2214 Do not call overridable methods in constructors PinprotectorPete O'Hanlon3-Jan-13 2:42 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM693-Jan-13 4:22 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM693-Jan-13 13:10 
GeneralRe: CA2214 Do not call overridable methods in constructors Pinmemberjschell3-Jan-13 9:16 
GeneralRe: CA2214 Do not call overridable methods in constructors [modified] PinmentorDaveyM693-Jan-13 12:36 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmemberBernhard Hiller3-Jan-13 23:48 
GeneralRe: CA2214 Do not call overridable methods in constructors Pinmemberjschell4-Jan-13 14:08 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM695-Jan-13 4:00 
GeneralRe: CA2214 Do not call overridable methods in constructors Pinmemberjschell6-Jan-13 5:42 
AnswerRe: CA2214 Do not call overridable methods in constructors PinmemberBobJanova3-Jan-13 2:41 
GeneralRe: CA2214 Do not call overridable methods in constructors PinmentorDaveyM693-Jan-13 13:29 
QuestionBind listview row color to active index Pinmemberbornefalk2-Jan-13 10:50 
QuestionUI Automation and MMC PinmemberRonNYC22-Jan-13 6:57 
Questionmove a newfolder form a system on other system on the network by c# Pinmembera2bj2-Jan-13 0:39 
AnswerRe: move a newfolder form a system on other system on the network by c# Pinmemberjibesh2-Jan-13 0:46 
AnswerRe: move a newfolder form a system on other system on the network by c# PinmemberSimon_Whale2-Jan-13 4:02 
Questiondata Set Not Coming In GridView Pinmemberaman11241-Jan-13 18:50 
AnswerRe: data Set Not Coming In GridView Pinmemberjibesh1-Jan-13 22:25 
GeneralRe: data Set Not Coming In GridView Pinmemberaman11242-Jan-13 0:35 
GeneralRe: data Set Not Coming In GridView Pinmemberjibesh2-Jan-13 0:36 
GeneralRe: data Set Not Coming In GridView PinmemberGugliMugli2-Jan-13 0:40 
GeneralRe: data Set Not Coming In GridView Pinmemberjibesh2-Jan-13 0:42 
GeneralRe: data Set Not Coming In GridView PinmemberGugliMugli2-Jan-13 0:57 
GeneralRe: data Set Not Coming In GridView Pinmemberjibesh2-Jan-13 1:02 
GeneralRe: data Set Not Coming In GridView PinmemberGugliMugli2-Jan-13 2:27 
GeneralRe: data Set Not Coming In GridView Pinmemberjibesh2-Jan-13 2:29 
AnswerRe: data Set Not Coming In GridView PinmvpRichard MacCutchan2-Jan-13 2:47 
GeneralRe: data Set Not Coming In GridView Pinmemberjibesh2-Jan-13 3:06 
GeneralRe: data Set Not Coming In GridView PinmemberGugliMugli2-Jan-13 3:18 
GeneralRe: data Set Not Coming In GridView PinmvpRichard MacCutchan2-Jan-13 5:15 
QuestionHow to show file association icon,one button and a progress bar on webbrowser control c# PinmemberTridip Bhattacharjee1-Jan-13 7:50 

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.1411022.1 | Last Updated 22 Nov 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid