예제 #1
0
        private static void CheckAllowedTypeReference(ITypeNode node, ISemanticModel semanticModel, DiagnosticContext context)
        {
            var type = semanticModel.GetTypeAtLocation(node);

            // The resolved type should be an interface
            IInterfaceType interfaceType = type.As <IInterfaceType>();

            if (interfaceType == null)
            {
                // We already checked this is not a type literal at this point
                context.Logger.QualifierTypeShouldBeAnInterfaceOrTypeLiteral(
                    context.LoggingContext,
                    node.LocationForLogging(context.SourceFile));
                return;
            }

            // The resolved type should be the special 'Qualifier' type or directly inherit from it
            if (!IsQualifierTypeOrDirectlyInheritsFromIt(interfaceType, semanticModel))
            {
                context.Logger.QualifierInterfaceTypeShouldBeOrInheritFromQualifier(
                    context.LoggingContext,
                    node.LocationForLogging(context.SourceFile),
                    Names.BaseQualifierType);
                return;
            }

            // All declarations need to be type-literal like
            var resolvedType = interfaceType.As <IResolvedType>();

            Contract.Assert(resolvedType != null);

            if (resolvedType.Properties == null)
            {
                return;
            }

            foreach (var property in resolvedType.Properties)
            {
                CheckResolvedPropertyIsAnAllowedType(property, semanticModel, context);
            }
        }