这真让我感到困惑。我试图删除只读的,更改名称的文件。我在这里做错了什么?
public abstract class CatalogBase<T> where T : class
{
protected readonly String DataPath;
protected readonly XmlSerializer Serializer;
private readonly XmlSerializerNamespaces _namespaces;
protected CatalogBase(String dataPath)
{
DataPath = dataPath;
Serializer = new XmlSerializer(typeof (T));
_namespaces = new XmlSerializerNamespaces();
_namespaces.Add(String.Empty, String.Empty);
}
public virtual void Write(T obj)
{
var streamWriter = new StreamWriter(DataPath);
Serializer.Serialize(streamWriter, obj, _namespaces);
streamWriter.Close();
}
public abstract IDictionary<String, T> Read();
}
编辑:
警告:
编辑2:
即使我按如下所示更改类,我仍然会收到错误消息:
public abstract class CatalogBase<T> where T : class
{
protected readonly String DataPath;
protected readonly XmlSerializer Serializer;
private readonly XmlSerializerNamespaces namespaces;
protected CatalogBase(String dataPath)
{
DataPath = dataPath;
Serializer = new XmlSerializer(typeof (T));
namespaces = new XmlSerializerNamespaces();
namespaces.Add(String.Empty, String.Empty);
}
public virtual void Write(T obj)
{
var streamWriter = new StreamWriter(DataPath);
Serializer.Serialize(streamWriter, obj, namespaces);
streamWriter.Close();
}
public abstract IDictionary<String, T> Read();
}
另外,我也忘记提及由于某种原因而遇到两个错误(完全相同的错误)。
最佳答案
看起来您具有以下条件:
CatalogBase<T>
。程序集不是标记为CLSCompliant MaterialCatalogBase : CatalogBase<T>
。程序集B 被标记为CLS的兼容如果是这种情况,则应使用CLSCompliant属性标记
CatalogBase<T>
类所在的程序集:[assembly: CLSCompliant(true)]
关于c# - 为什么我的类(class)不符合CLS?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15739511/