2013-04-01 107 views
7

这真让我感到困惑。我尝试删除只读,不断变化的名称..我在这里做错了什么?为什么我的课不符合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(); 
} 

编辑:

警告:

Warning 1 'Ar.ViewModel.Workspaces.MaterialCatalogBase': base type 'Or.Files.CatalogBase' is not CLS-compliant 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(); 
} 

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

+1

什么是你确切的警告信息接收? –

+0

我们不是编译器,所以请显示您获得非CLS合规性警告的位置。 – CodeCaster

+1

当我编译这个时,我实际上没有得到警告,一切看起来都很好。 –

回答

4

看起来你具备以下条件:

  • 大会一宣布CatalogBase<T>。组件A 不是,标记为CLSCompliant
  • 组件B引用程序集A.程序集B声明MaterialCatalogBase : CatalogBase<T>。组件B 标记为CLSCompliant

如果你的情况 - 那么组件,其中你CatalogBase<T>类位于应CLSCompliant属性标记:

[assembly: CLSCompliant(true)]