November Happy Hour will be moved to Thursday December 5th.

PropertyData.GetSetting() method is obsolete

Vote:
 

I am trying to use the code for a multi-select drop down list. 

public class PropertyDropdownCheckListControl : PropertyTextBoxControlBase
{
protected System.Web.UI.WebControls.ListBox listBox;

public override bool SupportsOnPageEdit
{
get { return false; }
}

public PropertyDropdownCheckList CategoryCheckBoxList
{
get { return PropertyData as PropertyDropdownCheckList; }
}

public override void CreateEditControls()
{
this.listBox = new ListBox();
listBox.SelectionMode = ListSelectionMode.Multiple;
listBox.ID = "DropdownCheckList";

CategorySettings settings = (CategorySettings)base.PropertyData.GetSetting(typeof(CategorySettings));

But receiving the warning given below for the last line in the code

Warning:

Episerver.Core.PropertyData.GetSetting(System.Type) is obsolete. This method does not support types property settings. Use extension method myContent.GetPropertySettings (p=>p.MainBody) or PropertySettingsResolver to resolve property settings.

can anyone help in this regard..

#148324
May 10, 2016 10:07
Vote:
 

Not sure if I'm giving you the best help, but mostly decompiling the obsolete method gives you a hint on what you're supposed to do:

      var settingsType = typeof(CategorySettings);
      var propertySettingsRepository = ServiceLocator.Current.GetInstance<IPropertySettingsRepository>();

      PropertySettingsWrapper propertySettingsWrapper = null;
      var settingsContainer = PropertyData.SettingsContainer;
      if (settingsContainer != null)
        propertySettingsWrapper = settingsContainer.GetSetting(settingsType);
      if (propertySettingsWrapper == null)
        propertySettingsWrapper = propertySettingsRepository.GetDefault(settingsType);
      if (propertySettingsWrapper != null)
      {
        var categorySettings = propertySettingsWrapper.PropertySettings as CategorySettings;
      }
#148444
May 13, 2016 0:32
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.