예제 #1
0
        private bool IsListType()
        {
            if (IsDictionaryType())
            {
                return(false);                 // Dictionary types are IEnumerable, so we don't want to include that
            }

            // First check for list types
            List <INamedTypeSymbol> isTypes = new List <INamedTypeSymbol>()
            {
                InCompilation.GetTypeByMetadataName(typeof(IEnumerable).FullName),
                InCompilation.GetTypeByMetadataName(typeof(IEnumerable <>).FullName),
                InCompilation.GetTypeByMetadataName(typeof(IReadOnlyList <>).FullName)
            };

            if (isTypes.Contains(NamedTypeSymbol.ConstructedFrom))
            {
                return(true);
            }

            // Then fall back to checking interfaces
            List <INamedTypeSymbol> listTypes = new List <INamedTypeSymbol>()
            {
                InCompilation.GetTypeByMetadataName(typeof(IList).FullName),
                InCompilation.GetTypeByMetadataName(typeof(IList <>).FullName),
            };

            return(TypeSymbol.Interfaces.Any(nt => listTypes.Contains(nt)));
        }
예제 #2
0
        private bool IsDictionaryType()
        {
            List <INamedTypeSymbol> dictTypes = new List <INamedTypeSymbol>()
            {
                InCompilation.GetTypeByMetadataName(typeof(IDictionary).FullName),
                InCompilation.GetTypeByMetadataName(typeof(IDictionary <,>).FullName)
            };

            return(TypeSymbol.Interfaces.Any(nt => dictTypes.Contains(nt)));
        }
예제 #3
0
        /// <summary>
        /// Gets the functional type of this class.  Generally, this is just the same as the provided symbol.  If the
        /// class does have an override class, that will be returned instead
        /// </summary>
        /// <param name="symb">The type symbol</param>
        /// <returns>The functional type</returns>
        private ITypeSymbol GetFunctionalType(ITypeSymbol symb)
        {
            INamedTypeSymbol funcTypeAttr   = InCompilation.GetTypeByMetadataName(typeof(FunctionalTypeAttribute).FullName);
            ITypeSymbol      functionalType = symb;

            foreach (AttributeData attr in symb.GetAttributes())
            {
                if (attr.AttributeClass.Equals(funcTypeAttr))
                {
                    functionalType = attr.ConstructorArguments[0].Value as INamedTypeSymbol;
                    break;
                }
            }

            return(functionalType);
        }
예제 #4
0
        private bool IsNullableType()
        {
            INamedTypeSymbol nullableSymb = InCompilation.GetTypeByMetadataName(typeof(Nullable <>).FullName);

            return(nullableSymb.Equals(TypeSymbol.OriginalDefinition));
        }