Ticket #2239: VariableStoreView.cs.patch

File VariableStoreView.cs.patch, 2.0 KB (added by bburlacu, 7 years ago)
  • 3.3/VariableStoreView.cs

     
    4141  public partial class VariableStoreView : AsynchronousContentView {
    4242    protected Dictionary<string, ListViewItem> itemListViewItemMapping;
    4343    protected TypeSelectorDialog typeSelectorDialog;
     44    private readonly Dictionary<Type, bool> serializableTypes;
    4445    protected bool validDragOperation;
    4546
    4647    public new VariableStore Content {
     
    5556    public VariableStoreView() {
    5657      InitializeComponent();
    5758      itemListViewItemMapping = new Dictionary<string, ListViewItem>();
     59      serializableTypes = new Dictionary<Type, bool>();
    5860      variableListView.SmallImageList.Images.AddRange(new Image[] {
    5961        HeuristicLab.Common.Resources.VSImageLibrary.Error,
    6062        HeuristicLab.Common.Resources.VSImageLibrary.Object,
     
    127129      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    128130        try {
    129131          return (object)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    130         } catch (Exception ex) {
     132        }
     133        catch (Exception ex) {
    131134          ErrorHandling.ShowErrorDialog(this, ex);
    132135        }
    133136      }
     
    411414    }
    412415
    413416    private bool IsSerializable(KeyValuePair<string, object> variable) {
     417      var type = variable.Value.GetType();
     418      if (serializableTypes.ContainsKey(type))
     419        return serializableTypes[type];
     420
    414421      var ser = new Serializer(variable, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()), "ROOT", true);
    415422      try {
    416         return ser.Count() > 0;
    417       } catch (PersistenceException) {
     423        bool serializable = ser.Count() > 0;
     424        serializableTypes[type] = serializable;
     425        return serializable;
     426      }
     427      catch (PersistenceException) {
     428        serializableTypes[type] = false;
    418429        return false;
    419430      }
    420431    }