开发者

Why isn't this CLS compatible?

I have the following Interfaces:

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

My implementation of the ITemplateItem looks like this:

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
}

But for the ITemplateCategory Implementation the compiler tells me that my class is not CLS Compliant.

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
}

Ok,

I could just ignore these warnings or turn them off by adding the CLSCompliant(false) attribute to my class. But I am curious why this happens. Expecially because the compiler does not complain about the inferface itself.

Does this happen for classes that expose Interfaces in general or did I just use a forbidden keyword?


Are these in different assemblies by any chance? Is ITemplateItem in an assembly which doesn't claim to be CLSCompliant? I think that would explain it - in which case, just make that assembly CLSCompliant - or possibly even just ITemplateItem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜