Exemplo n.º 1
0
        internal void DecodeInterfaceTypeAttribute(AttributeSyntax node, DiagnosticBag diagnostics)
        {
            Debug.Assert(!this.HasErrors);

            TypedConstant ctorArgument = this.CommonConstructorArguments[0];

            Debug.Assert(ctorArgument.Kind == TypedConstantKind.Enum || ctorArgument.Kind == TypedConstantKind.Primitive);

            ComInterfaceType interfaceType = ctorArgument.Kind == TypedConstantKind.Enum ?
                                             ctorArgument.DecodeValue <ComInterfaceType>(SpecialType.System_Enum) :
                                             (ComInterfaceType)ctorArgument.DecodeValue <short>(SpecialType.System_Int16);

            switch (interfaceType)
            {
            case Cci.Constants.ComInterfaceType_InterfaceIsDual:
            case Cci.Constants.ComInterfaceType_InterfaceIsIDispatch:
            case ComInterfaceType.InterfaceIsIInspectable:
            case ComInterfaceType.InterfaceIsIUnknown:
                break;

            default:
                // CS0591: Invalid value for argument to '{0}' attribute
                CSharpSyntaxNode attributeArgumentSyntax = this.GetAttributeArgumentSyntax(0, node);
                diagnostics.Add(ErrorCode.ERR_InvalidAttributeArgument, attributeArgumentSyntax.Location, node.GetErrorDisplayName());
                break;
            }
        }
Exemplo n.º 2
0
        internal void DecodeClassInterfaceAttribute(AttributeSyntax nodeOpt, DiagnosticBag diagnostics)
        {
            Debug.Assert(!this.HasErrors);

            TypedConstant ctorArgument = this.CommonConstructorArguments[0];

            Debug.Assert(ctorArgument.Kind == TypedConstantKind.Enum || ctorArgument.Kind == TypedConstantKind.Primitive);

            ClassInterfaceType interfaceType = ctorArgument.Kind == TypedConstantKind.Enum ?
                                               ctorArgument.DecodeValue <ClassInterfaceType>(SpecialType.System_Enum) :
                                               (ClassInterfaceType)ctorArgument.DecodeValue <short>(SpecialType.System_Int16);

            switch (interfaceType)
            {
            case ClassInterfaceType.None:
            case Cci.Constants.ClassInterfaceType_AutoDispatch:
            case Cci.Constants.ClassInterfaceType_AutoDual:
                break;

            default:
                // CS0591: Invalid value for argument to '{0}' attribute
                Location attributeArgumentSyntaxLocation = this.GetAttributeArgumentSyntaxLocation(0, nodeOpt);
                diagnostics.Add(ErrorCode.ERR_InvalidAttributeArgument, attributeArgumentSyntaxLocation, nodeOpt != null ? nodeOpt.GetErrorDisplayName() : "");
                break;
            }
        }