Esempio n. 1
0
        /// <summary>
        /// Creates a service.
        /// </summary>
        public ServiceInfo(string name, IEnumerable <ServiceMemberInfo> members, IEnumerable <ServiceAttributeInfo>?attributes = null, string?summary = null, IEnumerable <string>?remarks = null, params ServicePart[] parts)
            : base(name, attributes, summary, remarks, parts)
        {
            Members = members.ToReadOnlyList();

            ValidateName();
            ValidateNoDuplicateNames(Members, "service member");

            var unsupportedMember = Members.FirstOrDefault(x => !(x is ServiceMethodInfo || x is ServiceDtoInfo || x is ServiceEnumInfo || x is ServiceErrorSetInfo));

            if (unsupportedMember != null)
            {
                throw new InvalidOperationException($"Unsupported member type: {unsupportedMember.GetType()}");
            }

            m_membersByName = Members.GroupBy(x => x.Name).ToDictionary(x => x.First().Name, x => x.First());

            m_typesByName = new Dictionary <string, ServiceTypeInfo>();
            foreach (var fieldGroup in GetDescendants().OfType <ServiceFieldInfo>().GroupBy(x => x.TypeName))
            {
                var type = ServiceTypeInfo.TryParse(fieldGroup.Key, FindMember);
                if (type != null)
                {
                    m_typesByName.Add(fieldGroup.Key, type);
                }
                else
                {
                    AddValidationErrors(fieldGroup.Select(x => new ServiceDefinitionError($"Unknown field type '{x.TypeName}'.", x.GetPart(ServicePartKind.TypeName)?.Position)));
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Gets the field type for a field.
 /// </summary>
 public ServiceTypeInfo?GetFieldType(ServiceFieldInfo field) =>
 m_typesByName.TryGetValue(field.TypeName, out var type) ? type : ServiceTypeInfo.TryParse(field.TypeName, FindMember);