2012-04-16 19 views
0

我只是想知道,如果它可以檢查是否在對象果園1.3檢查,如果屬性存在

喜歡的東西存在的屬性/屬性:

if(widgetPart.RenderTitle.GetType().ToString() != null) {...} 

String.isNullOrEmpty(widgetPart.RenderTitle) 

它給我

'Orchard.Widgets.Models.Widg etPart'不包含 'RenderTitle'的定義,也沒有擴展方法'RenderTitle'。

回答

0

我得到我的解決辦法是這樣的:

var renderTitleObj = ((IContent)Model.ContentItem).As<WidgetPart>(); 
System.Reflection.PropertyInfo propInfoSrcObj = renderTitleObj.GetType().GetProperty("RenderTitle"); 
if (propInfoSrcObj != null) { renderTitle = Convert.ToBoolean(propInfoSrcObj.GetValue(renderTitleObj, null)); } 

感謝。

0

只要使用反射或更好的方式,請在使用它們之前檢查WidgetPart以獲取可用成員。這甚至不會編譯。