在使用VS 2012下的MVC 3解决方案时,运行代码分析后收到“DON'T”分析的消息似乎有些奇怪。这是因为提到“DON'T”分析中的类是由VS自动生成的(而非我)。要重现这个问题,您可以:1.将ADO.NET实体数据模型添加到解决方案中;2.在图表中添加数据库表(已存在于SQL Server中);3.重新构建解决方案,并添加控制器和cshtml视图(这些是自动生成的);4.从ANALYZE菜单运行代码分析。那么问题来了,我们该做什么:重构自动生成的代码还是忽略这个消息?以下是一个违反规则CA2214的自动生成类的示例:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Backoffice.Entities
{
using System;
using System.Collections.Generic;
public partial class BR_SIMUL_Supermarket_Product
{
public BR_SIMUL_Supermarket_Product()
{
this.BR_SIMUL_Supermarket_Product_Price = new HashSet<BR_SIMUL_Supermarket_Product_Price>();
}
public int product_id { get; set; }
public int category_id { get; set; }
public string product_name { get; set; }
public string product_measure { get; set; }
public bool product_active { get; set; }
public virtual BR_SIMUL_Supermarket_Category BR_SIMUL_Supermarket_Category { get; set; }
more stuff here...