好吧,我得到了下面的類,但產品總是空當我GetIstance();
Visual Studio中顯示:爲什麼它總是一個空值?
Field 'PageStyle.item' is never assigned to, and will always have its default value null
我怎樣才能解決這個問題?我究竟做錯了什麼?有沒有更好的方式做下面做的事情?
public class PageStyle
{
private static PageStyle _Instance = null;
// Instantiate variables relating to sitecore item paths.
Database webDB;
Sitecore.Data.Items.Item item;
// constructor
private PageStyle()
{
if (webDB != null)
{
webDB = Sitecore.Configuration.Factory.GetDatabase("web");
Sitecore.Data.Items.Item item = webDB.Items[StartItem];
}
}
// Method that gets instance
public static PageStyle GetInstance()
{
if (_Instance == null)
_Instance = new PageStyle();
return _Instance;
}
private void InitializeWebDB()
{
if (webDB == null)
{
webDB = Sitecore.Configuration.Factory.GetDatabase("web");
}
}
private void InitializeStartItem()
{
if (webDB != null)
{
item = webDB.Items[StartItem];
}
}
public string StartItem
{
get
{
return _startItem;
}
set
{
_startItem = value;
}
}
}
+1正是我要回答 – Nuffin 2012-01-18 09:12:45
尼斯,基本上是做這種方式我可以擺脫初始化WebDB()方法。如果工作,乾杯夥伴將標記爲答案。 – Anicho 2012-01-18 10:03:12