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