Esempio n. 1
0
        /// <inheritdoc/>
        public override bool CanAttach(INodePresenter nodePresenter)
        {
            // We are in a dictionary...
            var dictionaryDescriptor = nodePresenter.Descriptor as DictionaryDescriptor;

            if (dictionaryDescriptor == null)
            {
                return(false);
            }

            // ... that is not read-only...
            var memberCollection = (nodePresenter as MemberNodePresenter)?.MemberAttributes.OfType <MemberCollectionAttribute>().FirstOrDefault()
                                   ?? nodePresenter.Descriptor.Attributes.OfType <MemberCollectionAttribute>().FirstOrDefault();

            if (memberCollection?.ReadOnly == true)
            {
                return(false);
            }

            // ... can construct key type...
            if (!AddNewItemCommand.CanConstruct(dictionaryDescriptor.KeyType))
            {
                return(false);
            }

            // ... and can construct value type
            var elementType = dictionaryDescriptor.ValueType;

            return(AddNewItemCommand.CanAdd(elementType));
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public override bool CanAttach(INodePresenter nodePresenter)
        {
            // We are in a dictionary
            if (!(nodePresenter.Descriptor is DictionaryDescriptor dictionaryDescriptor))
            {
                return(false);
            }

            // It is not read-only
            var memberCollection = (nodePresenter as MemberNodePresenter)?.MemberAttributes
                                   .OfType <MemberCollectionAttribute>()
                                   .FirstOrDefault() ??
                                   nodePresenter.Descriptor.Attributes
                                   .OfType <MemberCollectionAttribute>()
                                   .FirstOrDefault();

            if (memberCollection?.ReadOnly == true)
            {
                return(false);
            }

            // It can construct the key type
            if (!AddNewItemCommand.CanConstruct(dictionaryDescriptor.KeyType))
            {
                return(false);
            }

            // And it can construct the value type
            var elementType = dictionaryDescriptor.ValueType;

            return(AddNewItemCommand.CanAdd(elementType));
        }