我有一个继承GlassBase的自动类。这些字段将自动从Sitecore中提取并映射到该类。我需要获取正在从其中提取字段的数据项的ID,但我不确定是如何提取的。
在其他项目中,我有继承自GlassControl的类,我可以获得GlassItem.Id,但是在这个项目中没有GlassControl,而是使用GlassBase。我怎样才能想到正在使用的玻璃制品?
public class MostRead : GlassBase
{
private readonly IPersonifyUserContext _userContext;
private readonly ISitecoreSearchProvider _searchProvider;
private readonly ISitecoreContext _sitecoreContext;
private readonly ICacheProvider _cacheProvider;
private readonly I___Global_Page_Configuration _currentItem;
public MostRead(IPersonifyUserContext userContext,ISitecoreContext context, ISitecoreSearchProvider searchProvider,ICacheProvider cache)
{
_cacheProvider = cache;
_userContext = userContext;
_searchProvider = searchProvider;
_sitecoreContext = context;
_currentItem = _sitecoreContext.GetCurrentItem<I___Global_Page_Configuration>();
}
[TopicsQueryAttirbute]
public IEnumerable<ITopic> AllTopics { get; set; }
[SitecoreField(IMost_ReadConstants.CountFieldName)]
public int Count { get; set; }
[SitecoreField(IMost_ReadConstants.PastXDaysFieldName)]
public int Days { get; set; }
[SitecoreField(IMost_ReadConstants.TopicsFieldName)]
public IEnumerable<Guid> Topics { get; set; }
[SitecoreField(IMost_ReadConstants.TitleFieldName)]
public string Title { get; set; }
[SitecoreField(IMost_ReadConstants.SiteFieldName)]
public string Site { get; set; }
}发布于 2018-01-03 22:04:53
GlassBase应该包含一个名为Id的属性:
public abstract class GlassBase : IGlassBase
{
[SitecoreId]
public virtual Guid Id{ get; private set;}
// Rest of class
}由于MostRead类继承自GlassBase,所以可以像通常访问属性那样访问Id属性:
在教室里:
// 'this' is redundant, but you could still use it
var id = this.Id;
// or
var id = Id;课外:
// Whatever your MostRead variable name is...
var mostRead = new MostRead();
var id = mostRead.Id;https://stackoverflow.com/questions/48085363
复制相似问题