为什么我的课不符合CLS? [英] Why is my class not CLS-compliant?

查看:598
本文介绍了为什么我的课不符合CLS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这我百思不得其解。我试着去掉只读,更改名称..我在做什么错在这里。

This really baffles me. I've tried removing the readonly, changing names.. What am I doing wrong here?

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:底座式
'或。 Files.CatalogBase'不是
符合CLS-C:_Center_Work_Programming_Cs\Ar\Ar\ViewModel\Workspaces\MaterialCatalogBase.cs 9月18日氩

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

Even if I change the class as below I still get the error:

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



另外,我忘了提,我得到两个(如出一辙错误),由于某种原因..

Also, I've forgotten to mention that I get two (exactly the same errors) for some reason.. ?

推荐答案

看起来你具备以下条件:?

Looks like you have the following:


  • 大会一个声明 CatalogBase< T> 。大会A 不是标记为CLSCompliant

  • 组件B引用组件A组件B声明 MaterialCatalogBase:CatalogBase< T> 。组件B的标记为CLSCompliant

  • Assembly A declares CatalogBase<T>. Assembly A is not marked as CLSCompliant
  • Assembly B references assembly A. Assembly B declares MaterialCatalogBase : CatalogBase<T>. Assembly B is marked as CLSCompliant

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

If it is your case - then assembly in which your CatalogBase<T> class located should be marked with CLSCompliant attribute:

[assembly: CLSCompliant(true)]

这篇关于为什么我的课不符合CLS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆