private static string[] ExtractPropertyValues(IType propertyType) { var unionType = propertyType.As <IUnionType>(); if (unionType != null) { // Currently, qualifier only supports literals return(unionType.Types.Select(t => t.Cast <IStringLiteralType>().Text).ToList().ToArray()); } var stringLiteral = propertyType.As <IStringLiteralType>(); Contract.Assert(stringLiteral != null, "linter"); return(new string[] { stringLiteral.Text }); }
/// <summary> /// Given a type, creates an IEnumerable of all the base <see cref="IInterfaceType"/> and all <see cref="IUnionType"/> types. /// </summary> /// <remarks> /// If IType is not a union or interface type, the function returns an enumerable of just that type. /// </remarks> private static HashSet <IType> ExpandUnionAndBaseInterfaceTypes(IType type, HashSet <IType> expandedTypes) { if ((type.Flags & (TypeFlags.Interface | TypeFlags.Union)) == TypeFlags.None) { return(new HashSet <IType> { type }); } if ((type.Flags & TypeFlags.Interface) != TypeFlags.None) { // Track the interface type as well, as it can contain symbols and properties in // addition to the base types expandedTypes.Add(type); var interfaceTypeWithMembers = type.As <IInterfaceType>(); if (interfaceTypeWithMembers.ResolvedBaseTypes?.Any() == true) { foreach (var baseType in interfaceTypeWithMembers.ResolvedBaseTypes) { expandedTypes.AddRange(ExpandUnionAndBaseInterfaceTypes(baseType, expandedTypes)); } } } else { Contract.Assert((type.Flags & TypeFlags.Union) != TypeFlags.None); var unionType = type.As <IUnionType>(); if (unionType.Types?.Any() == true) { foreach (var unionTypesType in unionType.Types) { expandedTypes.AddRange(ExpandUnionAndBaseInterfaceTypes(unionTypesType, expandedTypes)); } } } return(expandedTypes); }
/// <nodoc /> public static bool IsMutable([CanBeNull] this IType type) { if (IsMutable(type?.Symbol?.Name)) { return(true); } // If the type is generic, need to check type arguments var typeReference = type.As <ITypeReference>(); if (typeReference != null && typeReference.TypeArguments?.Count > 0) { return(typeReference.TypeArguments.Any(t => IsMutable(t))); } return(IsMutable(type?.Symbol?.Name)); }