我有一个公共类ArticleDao,但当我尝试在另一个文件中使用它时,它会显示“ArticleDa由于其保护级别而无法访问”。下面是整个类:
class ArticleDao : IArticleDao
{
private readonly ContentManager _contentManager;
private static readonly char[] DelimiterChars = { '|', '\n' };
private const int ArticlePagingSize = 500;
public ArticleDao()
{
_contentManager = new ContentManager();
}
private Image GetImage(XElement element)
{
var image = new Image();
if (String.IsNullOrEmpty((String)element))
{
return image;
}
XElement imageElement = element.Element("img");
if (imageElement != null)
{
image.Url = (String)imageElement.Attribute("src");
}
return image;
}
private Link GetLink(XElement element)
{
var link = new Link();
if (String.IsNullOrEmpty((String)element))
{
return link;
}
XElement anchorElement = element.Element("a");
if (anchorElement != null)
{
link.Url = (String)anchorElement.Attribute("href");
link.Text = (String)anchorElement;
}
return link;
}
public Article GetArticle(long id, string html)
{
var a = new Article();
long testid = 556;
if (id == testid)
{
var x = 1;
}
XDocument xdoc = XDocument.Parse(html);
var xElement = xdoc.Element("root");
if (xElement != null)
{
XElement articleElem = xElement.Element("Event");
if (articleElem != null)
{
a = new Article();
a.Id = id.ToString(CultureInfo.InvariantCulture);
a.Title = (String)articleElem.Element("Title");
a.PublishedDate = GetDateTime((String)articleElem.Element("PublishedDate"));
a.SubHeader = (String)articleElem.Element("SubHeader");
a.Image = GetImage(articleElem.Element("Image"));
a.Caption = (String)articleElem.Element("Caption");
a.Body = (String)articleElem.Element("Body");
a.Url = GetLink(articleElem.Element("Url"));
}
}
return a;
}
public Article GetArticle(Int64 ektronContentId)
{
var item = _contentManager.GetItem(ektronContentId);
return GetArticle(ektronContentId, item.Html);
}
public IEnumerable<Article> GetArticles(Int64 folderId)
{
int count;
IEnumerable<Article> articles = new List<Article>(ArticlePagingSize);
do
{
var criteria = new ContentCriteria();
criteria.AddFilter(ContentProperty.FolderId, CriteriaFilterOperator.EqualTo, folderId);
criteria.PagingInfo.RecordsPerPage = ArticlePagingSize;
var articleContentData = _contentManager.GetList(criteria);
count = articleContentData == null ? 0 : articleContentData.Count;
articles = articles.Concat(_contentManager.GetList(criteria)
.Select(i => GetArticle(i.Id, i.Html)));
} while (count == ArticlePagingSize);
return articles;
}
private DateTime GetDateTime(string date)
{
DateTime dt;
DateTime.TryParse(date, out dt);
return dt;
}
}
构造函数是公共的。我甚至尝试用“public”替换所有“private”实例,但它仍然表示无法访问。这是我试图调用它的行:
private static IArticleDao _articleDao;
public static IArticleDao ArticleDao
{
get { return _articleDao ?? (_articleDao = new ArticleDao()); }
}
其中“_articleDao=new articleDao()”是错误所在。
我特别困惑,因为要创建ArticleDao和IArticleDao,我基本上只是复制了EventDao和IEventDao,并将“Event”替换为“Article”
private static IEventDao _eventDao;
public static IEventDao EventDao
{
get { return _eventDao ?? (_eventDao = new EventDao()); }
}
但ArticleDao不起作用。