可访问性不一致:属性 类型 - 如果 class 和列表都是 public 如何解决
Inconsistent accessibility: property type - How to solve it if both class and list was public
我有定制的清单 class 短篇小说是代码
[DataContract]
[KnownType(typeof(Offer))]
[KnownType(typeof(Category))]
public class HomePage
{
private List<Category> _Categories;
private List<Offer> _Featured;
[DataMember]
public List<Category> Categories { get { return _Categories; } set { _Categories = value; } }
[DataMember]
public List<Offer> Featured { get { return _Featured; } set { _Featured = value; } }
这是我的 class
public class Offers
{
public string offerTitle {get; set;}
public string offerDescription{get; set;}
public string offerLocation{get; set;}
}
无论如何,当我尝试构建项目时出现此错误
Inconsistent accessibility: property type 'System.Collections.Generic.List' is less accessible than property 'OffTag.HomePage.Featured'
注意:列表和 class 都存在于不同的文件中 我不知道这是否是问题所在,但我认为值得一提,因为我正在开发 WCF Web 服务
编译以下代码。在您的示例中,有一个名为 class 的 Offer,但它必须命名为 Offer 而最后没有 "s"。我删除了不相关的类别。
[DataContract]
[KnownType(typeof (Offer))]
public class HomePage {
[DataMember]
public List<Offer> Featured { get; set; }
}
internal class Program {
private static void Main(string[] args) {
}
}
public class Offer {
public string offerTitle { get; set; }
public string offerDescription { get; set; }
public string offerLocation { get; set; }
}
一般错误是 "something in your class is visible to a scope that can't also see the type of the thing." 在这种情况下,错误意味着您有一个类型不是 public 的属性 (Featured
)。
这有点误导,因为该类型被描述为 System.Collections.Generic.List
,但实际上它是您的 Offer
class 而不是 public。我注意到您已经共享了 Offers
的代码,这是一个不同的 class - 也许这是一个简单的错字?
确保 Offer
为 public 错误将得到纠正。
我有定制的清单 class 短篇小说是代码
[DataContract]
[KnownType(typeof(Offer))]
[KnownType(typeof(Category))]
public class HomePage
{
private List<Category> _Categories;
private List<Offer> _Featured;
[DataMember]
public List<Category> Categories { get { return _Categories; } set { _Categories = value; } }
[DataMember]
public List<Offer> Featured { get { return _Featured; } set { _Featured = value; } }
这是我的 class
public class Offers
{
public string offerTitle {get; set;}
public string offerDescription{get; set;}
public string offerLocation{get; set;}
}
无论如何,当我尝试构建项目时出现此错误
Inconsistent accessibility: property type 'System.Collections.Generic.List' is less accessible than property 'OffTag.HomePage.Featured'
注意:列表和 class 都存在于不同的文件中 我不知道这是否是问题所在,但我认为值得一提,因为我正在开发 WCF Web 服务
编译以下代码。在您的示例中,有一个名为 class 的 Offer,但它必须命名为 Offer 而最后没有 "s"。我删除了不相关的类别。
[DataContract]
[KnownType(typeof (Offer))]
public class HomePage {
[DataMember]
public List<Offer> Featured { get; set; }
}
internal class Program {
private static void Main(string[] args) {
}
}
public class Offer {
public string offerTitle { get; set; }
public string offerDescription { get; set; }
public string offerLocation { get; set; }
}
一般错误是 "something in your class is visible to a scope that can't also see the type of the thing." 在这种情况下,错误意味着您有一个类型不是 public 的属性 (Featured
)。
这有点误导,因为该类型被描述为 System.Collections.Generic.List
,但实际上它是您的 Offer
class 而不是 public。我注意到您已经共享了 Offers
的代码,这是一个不同的 class - 也许这是一个简单的错字?
确保 Offer
为 public 错误将得到纠正。