为什么我的课不是CLS

这真让我感到困惑。 我尝试删除只读,不断变化的名称..我在这里做错了什么?

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

EDIT2:

即使我改变了下面的类,我仍然得到错误:

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

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


看起来你有以下几点:

  • 大会A声明CatalogBase<T> 。 程序集A 标记为CLSCompliant
  • 程序集B引用程序集A.程序集B声明MaterialCatalogBase : CatalogBase<T> 。 组件B 标记为CLSCompliant
  • 如果是你的情况 - 那么你的CatalogBase<T>类所在的程序集应该用CLSCompliant属性标记:

    [assembly: CLSCompliant(true)]
    
    链接地址: http://www.djcxy.com/p/70483.html

    上一篇: Why is my class not CLS

    下一篇: Unable to receive proper UDP packets using SSDP