public override object Deserialize(Cell _data, ConversionContext _context = null)
        {
            object data =  base.Deserialize(_data);
            DropdownButton ddButton;

            if (data == null) {
                ddButton = new DropdownButton();
            }
            else {
                ddButton = data as DropdownButton;
            }

            if (_context == null ||
                _context.Field == null ||
                _context.Field.Metadata == null) {
                return ddButton;
            }

            if (!_context.Field.Metadata.IsLoaded) {
                _context.Field.Metadata.Load();
            }

            var metadata = _context.Field.Metadata.FirstOrDefault(m => m.Key == ModuleRepository.DropdownButtonMetadataKey);

            if (metadata != null &&
                !String.IsNullOrWhiteSpace(metadata.Value)) {

                var json = new JavaScriptSerializer();
                var items = json.Deserialize<string[]>(metadata.Value);

                if (items != null) {
                    foreach (var i in items) {
                        if (!String.IsNullOrWhiteSpace(i)) {
                            // avoid adding empty entries to the dictionary
                            ddButton.ValidValues.Add(i.EscapeName(), i);
                        }
                    }
                }
            }

            return ddButton;
        }
Beispiel #2
0
        public void Test_Deserialize_DropdownButton_Null()
        {
            // Arrange
            var value = new DropdownButton { SelectedValue = null };
            object retData = SerializeAndDeserialize(value);

            // Assert
            Assert.IsNotNull(retData);
            Assert.IsInstanceOfType(retData, typeof(DropdownButton));

            DropdownButton result = (DropdownButton)retData;

            Assert.IsNull(result.SelectedValue);
        }