我有以下接口:

public interface ITemplateItem
{
    int Id { get; set; }
    String Name { get; set; }
    String Text { get; set; }
    int  CategoryId { get; set; }
    int  Typ { get; set; }
}

public interface ITemplateCategory
{
    int Id { get; set; }
    String Name { get; set; }

    List<ITemplateItem> TemplateItems { get; set; }
    void Add(ITemplateItem item);
    void Remove(ITemplateItem item);
    ITemplateItem CreateTemplateItem();
}

我的ITemplateItem的实施看起来是这样的:

public class MyTemplateItem : ITemplateItem
{
    #region ITemplateItem Member
    public int Id { get; set; }
    public String Name { get; set; }
    public String Text { get; set; }
    public int CategoryId { get; set; }
    public int Typ { get; set; }
    #endregion
}

但对于ITemplateCategory执行编译器告诉我,我的课是不符合CLS。

public class MyTemplateCategory : ITemplateCategory
{
    #region ITemplateCategory Member
    public int Id { get; set; }
    public String Name { get; set; }

    // Warning: type of TemplateItems not CLS-Compliant
    public List<ITemplateItem> TemplateItems { get; set; } 

    // Warning: Argument not CLS-Compliant
    public void Add(ITemplateItem item)
    {
        throw new NotImplementedException();
    }

    // Warning: Argument not CLS-Compliant
    public void Remove(ITemplateItem item)
    {
        throw new NotImplementedException();
    }

    // Warning: Return type not CLS-Compliant
    public ITemplateItem CreateTemplateItem() 
    {
        throw new NotImplementedException();
    }
    #endregion
}

确定,

我可以忽略这些警告或通过添加CLSCompliant(假)属性上我的课将其关闭。 不过,我很好奇为什么发生这种情况。 Expecially因为编译器不抱怨inferface本身。

这是否发生了暴露接口,一般还是我只是用一种禁止关键字类?

有帮助吗?

解决方案

通过任何机会这些是在不同的组件?是ITemplateItem在不宣称自己是CLSCompliant组装?我的认为的会解释 - 在这种情况下,才使该程序集CLSCompliant - 或者甚至可能只是ITemplateItem

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top