[英]Is warning CA1001 implement IDisposable negligible
I am using Repository
pattern and having my general repository class 我正在使用
Repository
模式并拥有我的通用存储库类
public class GeneralRepository<T> where T:class
{
private Context con = new Context();
protected DbSet<T> Dbset { get; set; }
public GeneralRepository()
{
Dbset = con.Set<T>();
}
public IEnumerable<T> GetAll()
{
return Dbset;
}
public T SelectByID(int? id)
{
var rec = Dbset.Find(id);
return rec;
}
public void AddRecord(T entity)
{
Dbset.Add(entity);
}
public void EditRecord(T entity)
{
con.Entry(entity).State = EntityState.Modified;
}
public void Detach(T entity)
{
con.Entry(entity).State = EntityState.Detached;
}
public void Save()
{
con.SaveChanges();
}
}
There are multiple native repositories which are inheriting my General repository like: 有多个本机存储库继承我的General存储库,如:
public class EmailAssignRepository:GeneralRepository<EmailAssign>
public class DepartmentRepository:GeneralRepository<Department>
Everything is running fine in my code , but it gave me warning when I run code analysis. 我的代码中的一切运行正常,但是当我运行代码分析时它给了我警告。 What does it mean?
这是什么意思? is it negligible?
它可以忽略不计吗? If not how to overcome this warning?
如果不是如何克服这个警告?
A class implements the
IDisposable
interface to dispose of unmanaged resources that it owns.类实现
IDisposable
接口以处置它拥有的非托管资源。 An instance field that is anIDisposable
type indicates that the field owns an unmanaged resource.IDisposable
类型的实例字段表示该字段拥有非托管资源。 A class that declares anIDisposable
field indirectly owns an unmanaged resource and should implement theIDisposable
interface.声明
IDisposable
字段的类间接拥有非托管资源,并应实现IDisposable
接口。 If the class does not directly own any unmanaged resources, it should not implement a finalizer.如果类不直接拥有任何非托管资源,则不应实现终结器。
Cause: 原因:
A class declares and implements an instance field that is a
System.IDisposable
type and the class does not implementIDisposable
.类声明并实现一个
System.IDisposable
类型的实例字段,该类不实现IDisposable
。
How to Fix Violations 如何修复违规行为
To fix a violation of this rule, implement
IDisposable
and from theSystem.IDisposable.Dispose
method call theDispose
method of the field.要修复违反此规则的问题,请实现
IDisposable
并从System.IDisposable.Dispose
方法调用该字段的Dispose
方法。
And see this: How to implement IDisposable inheritance in a repository? 并看到这个: 如何在存储库中实现IDisposable继承?
When to Suppress Warnings (and your question is it negligible ? No) 什么时候禁止警告(你的问题可以忽略不计?不)
Do not suppress a warning from this rule.
请勿禁止此规则发出警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.