Esempio n. 1
0
 private ServiceTypeInfo(ServiceTypeKind kind, ServiceDtoInfo dto = null, ServiceEnumInfo @enum = null, ServiceTypeInfo valueType = null)
 {
     Kind      = kind;
     Dto       = dto;
     Enum      = @enum;
     ValueType = valueType;
 }
Esempio n. 2
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. 3
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);
Esempio n. 4
0
 /// <summary>
 /// Create a map type.
 /// </summary>
 public static ServiceTypeInfo CreateMap(ServiceTypeInfo valueType)
 {
     return(new ServiceTypeInfo(ServiceTypeKind.Map, valueType: valueType));
 }
Esempio n. 5
0
 /// <summary>
 /// Create an array type.
 /// </summary>
 public static ServiceTypeInfo CreateArray(ServiceTypeInfo valueType)
 {
     return(new ServiceTypeInfo(ServiceTypeKind.Array, valueType: valueType));
 }
Esempio n. 6
0
 /// <summary>
 /// Create a service result type.
 /// </summary>
 public static ServiceTypeInfo CreateResult(ServiceTypeInfo valueType)
 {
     return(new ServiceTypeInfo(ServiceTypeKind.Result, valueType: valueType));
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the field type for a field.
 /// </summary>
 public ServiceTypeInfo GetFieldType(ServiceFieldInfo field)
 {
     return(ServiceTypeInfo.Parse(field.TypeName, FindMember, field.Position));
 }
Esempio n. 8
0
 /// <summary>
 /// Gets the type of the specified name.
 /// </summary>
 public ServiceTypeInfo GetType(string typeName)
 {
     return(ServiceTypeInfo.Parse(typeName, FindMember));
 }
Esempio n. 9
0
 /// <summary>
 /// Create a map type.
 /// </summary>
 public static ServiceTypeInfo CreateMap(ServiceTypeInfo valueType) => new ServiceTypeInfo(ServiceTypeKind.Map, valueType: valueType);
Esempio n. 10
0
 /// <summary>
 /// Create an array type.
 /// </summary>
 public static ServiceTypeInfo CreateArray(ServiceTypeInfo valueType) => new ServiceTypeInfo(ServiceTypeKind.Array, valueType: valueType);
Esempio n. 11
0
 /// <summary>
 /// Create a service result type.
 /// </summary>
 public static ServiceTypeInfo CreateResult(ServiceTypeInfo valueType) => new ServiceTypeInfo(ServiceTypeKind.Result, valueType: valueType);
Esempio n. 12
0
 internal static void ValidateTypeName(string name, NamedTextPosition position)
 {
     ServiceTypeInfo.Parse(name, x => s_validNameRegex.IsMatch(x) ? new ServiceDtoInfo(x) : null, position);
 }