Domanda

Ho le seguenti interfacce:

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

Il mio attuazione del ITemplateItem assomiglia a questo:

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
}

Ma per l'attuazione ITemplateCategory il compilatore mi dice che la mia classe non è compatibile con 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
}

Ok,

ho potuto semplicemente ignorare questi avvertimenti o spegnerli aggiungendo l'attributo CLSCompliant (false) per la mia classe. Ma io sono curioso di sapere perchè questo accade. Specialmente perché il compilatore non si lamenta l'inferface stesso.

Questo accade per le classi che espongono interfacce in generale o ho appena usare una parola chiave proibita?

È stato utile?

Soluzione

Sono questi in diverse assemblee per caso? È ITemplateItem in un'assemblea che non ha la pretesa di essere CLSCompliant? I pensare che sarebbe spiegare - in questo caso, basta fare quell'assemblea CLSCompliant -. O forse anche solo ITemplateItem

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top