8

这真的让我很困惑。我已经尝试删除只读的,更改名称..我在这里做错了什么?

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();
}

编辑:

警告:

警告 1“Ar.ViewModel.Workspaces.MaterialCatalogBase”:基本类型“Or.Files.CatalogBase”不符合 CLS C:_Center_Work_Programming_Cs\Ar\Ar\ViewModel\Workspaces\MaterialCatalogBase.cs 9 18 Ar

编辑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();
}

另外,我忘了提到由于某种原因我得到了两个(完全相同的错误)..?

4

1 回答 1

7

看起来你有以下内容:

  • 大会 A 声明CatalogBase<T>。程序集 A标记为 CLSCompliant
  • 程序集 B 引用程序集 A。程序集 B 声明MaterialCatalogBase : CatalogBase<T>. 程序集 B标记为 CLSCompliant

如果是你的情况 - 那么你的CatalogBase<T>类所在的程序集应该用 CLSCompliant 属性标记:

[assembly: CLSCompliant(true)]
于 2013-04-01T08:41:41.867 回答