Exemple #1
0
        /// <summary>
        /// Creates a service.
        /// </summary>
        public ServiceInfo(string name, IEnumerable <IServiceMemberInfo> members = null, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, IEnumerable <string> remarks = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Members    = members.ToReadOnlyList();
            Attributes = attributes.ToReadOnlyList();
            Summary    = summary ?? "";
            Remarks    = remarks.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);

            foreach (var member in Members)
            {
                if (!(member is ServiceMethodInfo) && !(member is ServiceDtoInfo) && !(member is ServiceEnumInfo) && !(member is ServiceErrorSetInfo))
                {
                    throw new ServiceDefinitionException($"Unsupported member type '{member.GetType()}'.");
                }
            }

            ServiceDefinitionUtility.ValidateNoDuplicateNames(Members, "service member");
            m_membersByName = new ReadOnlyDictionary <string, IServiceMemberInfo>(Members.ToDictionary(x => x.Name, x => x));

            foreach (var field in Methods.SelectMany(x => x.RequestFields.Concat(x.ResponseFields)).Concat(Dtos.SelectMany(x => x.Fields)))
            {
                GetFieldType(field);
            }
        }
Exemple #2
0
 internal static void ValidateName(string name, NamedTextPosition position)
 {
     if (!IsValidName(name))
     {
         throw new ServiceDefinitionException($"Invalid name '{name}'.", position);
     }
 }
        /// <summary>
        /// Creates an exception.
        /// </summary>
        public ServiceDefinitionException(string error, NamedTextPosition position = null, Exception innerException = null)
            : base("", innerException)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            Error    = error;
            Position = position;
        }
        /// <summary>
        /// Creates an attribute.
        /// </summary>
        public ServiceAttributeInfo(string name, IEnumerable <ServiceAttributeParameterInfo> parameters = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Parameters = parameters.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
            ServiceDefinitionUtility.ValidateNoDuplicateNames(Parameters, "attribute parameter");
        }
Exemple #5
0
        /// <summary>
        /// Creates an enum value.
        /// </summary>
        public ServiceEnumValueInfo(string name, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Attributes = attributes.ToReadOnlyList();
            Summary    = summary ?? "";
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
        }
Exemple #6
0
        /// <summary>
        /// Creates a DTO.
        /// </summary>
        public ServiceDtoInfo(string name, IEnumerable <ServiceFieldInfo> fields = null, IEnumerable <ServiceAttributeInfo> attributes = null, string summary = null, IEnumerable <string> remarks = null, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name       = name;
            Fields     = fields.ToReadOnlyList();
            Attributes = attributes.ToReadOnlyList();
            Summary    = summary ?? "";
            Remarks    = remarks.ToReadOnlyList();
            Position   = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
            ServiceDefinitionUtility.ValidateNoDuplicateNames(Fields, "field");
        }
        /// <summary>
        /// Creates an attribute parameter.
        /// </summary>
        public ServiceAttributeParameterInfo(string name, string value, NamedTextPosition position = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            Name     = name;
            Value    = value;
            Position = position;

            ServiceDefinitionUtility.ValidateName(Name, Position);
        }
Exemple #8
0
        internal static ServiceTypeInfo Parse(string text, Func <string, IServiceMemberInfo> findMember, NamedTextPosition position = null)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            var primitiveTuple = s_primitiveTuples.FirstOrDefault(x => text == x.Item2);

            if (primitiveTuple != null)
            {
                return(CreatePrimitive(primitiveTuple.Item1));
            }

            string resultValueType = TryPrefixSuffix(text, "result<", ">");

            if (resultValueType != null)
            {
                return(CreateResult(Parse(resultValueType, findMember, position)));
            }

            string arrayValueType = TryPrefixSuffix(text, "", "[]");

            if (arrayValueType != null)
            {
                return(CreateArray(Parse(arrayValueType, findMember, position)));
            }

            string mapValueType = TryPrefixSuffix(text, "map<", ">");

            if (mapValueType != null)
            {
                return(CreateMap(Parse(mapValueType, findMember, position)));
            }

            if (findMember != null)
            {
                var member = findMember(text);

                var dto = member as ServiceDtoInfo;
                if (dto != null)
                {
                    return(CreateDto(dto));
                }

                var @enum = member as ServiceEnumInfo;
                if (@enum != null)
                {
                    return(CreateEnum(@enum));
                }
            }

            throw new ServiceDefinitionException($"Unknown field type '{text}'.", position);
        }
Exemple #9
0
 internal static void ValidateTypeName(string name, NamedTextPosition position)
 {
     ServiceTypeInfo.Parse(name, x => s_validNameRegex.IsMatch(x) ? new ServiceDtoInfo(x) : null, position);
 }