Note that there are some explanatory texts on larger screens.

plurals
  1. POOverridable Methods In Constructors -Help to Fix
    text
    copied!<p>Im attempting to use fxCop on a C# Project as kind of basis for C# coding standards.</p> <p>The project Im using is called S#arp Architecture and is freely available here: <a href="http://code.google.com/p/sharp-architecture/" rel="nofollow noreferrer">S#Arp Arch</a></p> <p>Now if I run fxCop (most things have been fixed already) I need to fix the CA2214 fxcop error for overridable methods in contructors.</p> <p>At the moment a piece of violating code looks like this:</p> <pre><code>public class Region : Entity, IHasAssignedId&lt;int&gt; { public Region(string description) { Check.Require(!string.IsNullOrEmpty(description)); this.Description = description; } protected Region() { } [DomainSignature] &gt; public virtual string Description { get; protected set; } public virtual void SetAssignedIdTo(int assignedId) { Id = assignedId; } } </code></pre> <p>Most of it is called in this way in the other cd files:</p> <pre><code>public static RegionDto Create(Region region) { if (region == null) { return null; } return new RegionDto() { Id = region.Id, &gt; Description = region.Description }; } </code></pre> <p>I have tried changing the type of method (private/protected etc) but there is often conflicting needs by fxCop and the unit tests, fxcop saying it doesnt like contructors with virtual methods but the unit saying that the methods should be public/protected virtual or protected internal virtual, catch 22 a lil bit?</p> <p>So any help to fix this fxcop rule would be appreciated, thanks.</p> <p>(The error occurs on the line marked with a >, the virtual get set method and when changed the other > is where it complains)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload