我正在尝试消除我们在整个解决方案中遇到的所有符合 CLS 的错误。虽然我已经设法整理出几个(例如以下划线开头的公共变量并使用无符号整数),但有一些我似乎无法找到它们失败的原因。
我已经粘贴了与其中一个问题相关的所有代码,有相当多的代码,但它只包含一个表单构造函数、接口和实现该接口的类。
VB.Net 表单构造函数(警告在unitOfWork
参数上并且读取参数“unitOfWork”的类型不符合 CLS:
Public Sub New(ByRef unitOfWork As IUnitOfWork)
MyBase.New()
InitializeComponent()
_unitOfWork = unitOfWork
End Sub
界面IUnitOfWork
如下:
public interface IUnitOfWork : IDisposable
{
bool IsInTransaction { get; }
bool IsDirty { get; }
object BeginTransaction();
object BeginTransaction(IsolationLevel isolationLevel);
void Commit();
void Rollback();
object Session { get; }
}
接口的唯一实现(因此将传递给表单构造函数的实例)是这样的:
public class UnitOfWork : IUnitOfWork
{
private ISession _session;
public UnitOfWork(SMSession session)
{
if (session == null)
{
throw new ArgumentNullException("Session wasn't supplied");
}
this._session = (ISession)session.OpenSession();
}
public bool IsInTransaction
{
get { return this._session.Transaction.IsActive; }
}
public bool IsDirty
{
get { return this._session.IsDirty(); }
}
public object Session
{
get { return this._session; }
}
public object BeginTransaction()
{
return this._session.BeginTransaction(IsolationLevel.ReadCommitted);
}
public object BeginTransaction(IsolationLevel isolationLevel)
{
return this._session.BeginTransaction(isolationLevel);
}
public void Commit()
{
if (this._session.Transaction == null)
{
throw new NullReferenceException
("The Transaction has not been initialised");
}
this._session.Transaction.Commit();
}
public void Rollback()
{
if (this._session.Transaction == null)
{
throw new NullReferenceException
("The Transaction has not been initialised");
}
this._session.Transaction.Rollback();
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
this._session.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
if (this._session != null)
{
this._session.Dispose();
}
Dispose(true);
GC.SuppressFinalize(this);
}
}
我要么对这个问题视而不见(可能是我多年来一直盯着这个问题的情况!),或者还有另一个我不知道的 CLS 合规限制。有什么建议么?