Ejemplo n.º 1
0
        private protected ServiceElementWithAttributesInfo(IEnumerable <ServiceAttributeInfo> attributes, IReadOnlyList <ServicePart> parts)
            : base(parts)
        {
            Attributes = attributes.ToReadOnlyList();

            var obsoleteAttributes = GetAttributes("obsolete");

            if (obsoleteAttributes.Count > 1)
            {
                AddValidationError(ServiceDefinitionUtility.CreateDuplicateAttributeError(obsoleteAttributes[1]));
            }
            var obsoleteAttribute = obsoleteAttributes.Count == 0 ? null : obsoleteAttributes[0];

            if (obsoleteAttribute != null)
            {
                IsObsolete = true;

                foreach (var obsoleteParameter in obsoleteAttribute.Parameters)
                {
                    if (obsoleteParameter.Name == "message")
                    {
                        ObsoleteMessage = obsoleteParameter.Value;
                    }
                    else
                    {
                        AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(obsoleteAttribute.Name, obsoleteParameter));
                    }
                }
            }

            var tagNames      = new List <string>();
            var tagAttributes = GetAttributes("tag");

            foreach (var tagAttribute in tagAttributes)
            {
                string tagName = null;
                foreach (var tagParameter in tagAttribute.Parameters)
                {
                    if (tagParameter.Name == "name")
                    {
                        tagName = tagParameter.Value;
                    }
                    else
                    {
                        AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(tagParameter.Name, tagParameter));
                    }
                }

                if (tagName != null)
                {
                    tagNames.Add(tagName);
                }
                else
                {
                    AddValidationError(new ServiceDefinitionError("'tag' attribute is missing required 'name' parameter.", tagAttribute.Position));
                }
            }

            TagNames = tagNames;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a field.
        /// </summary>
        public ServiceFieldInfo(string name, string typeName, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, params ServicePart[] parts)
            : base(attributes, parts)
        {
            Name     = name ?? throw new ArgumentNullException(nameof(name));
            TypeName = typeName ?? throw new ArgumentNullException(nameof(typeName));
            Summary  = summary ?? "";

            ValidateName();

            var requiredAttributes = GetAttributes("required");

            if (requiredAttributes.Count > 1)
            {
                AddValidationError(ServiceDefinitionUtility.CreateDuplicateAttributeError(requiredAttributes[1]));
            }
            var requiredAttribute = requiredAttributes.Count == 0 ? null : requiredAttributes[0];

            if (requiredAttribute != null)
            {
                IsRequired = true;

                foreach (var requiredParameter in requiredAttribute.Parameters)
                {
                    AddValidationError(ServiceDefinitionUtility.CreateUnexpectedAttributeParameterError(requiredAttribute.Name, requiredParameter));
                }
            }
        }