예제 #1
0
        public void SetItem(DateInputItemType itemType, DateInputContextItem item)
        {
            Guard.ArgumentNotNull(nameof(item), item);

            if (_haveValue && item.ValueSpecified)
            {
                throw new InvalidOperationException($"Value cannot be specified for both <{GetTagNameForItemType(itemType)}> and the parent <{RootTagName}>.");
            }

            var tagName = GetTagNameForItemType(itemType);

            if (Fieldset != null)
            {
                throw new InvalidOperationException($"<{tagName}> must be inside <{FieldsetTagName}>.");
            }

            if (_items.Count != 0)
            {
                if (_items.ContainsKey(itemType))
                {
                    throw ExceptionHelper.OnlyOneElementIsPermittedIn(tagName, DateInputTagHelper.TagName);
                }

                var subsequentItems = _items.Where(kvp => kvp.Key > itemType).ToArray();

                if (subsequentItems.Length != 0)
                {
                    throw ExceptionHelper.ChildElementMustBeSpecifiedBefore(
                              tagName,
                              GetTagNameForItemType(subsequentItems[0].Key));
                }
            }

            _items.Add(itemType, item);
        }
예제 #2
0
 internal static string GetTagNameForItemType(DateInputItemType itemType) => itemType switch
 {