Exemplo n.º 1
0
        private Attribute?ParseBodyAttribute(AttributeData attributeData, ISymbol declaringSymbol, DiagnosticReporter diagnosticReporter)
        {
            BodyAttribute?attribute = null;

            if (attributeData.ConstructorArguments.Length == 0)
            {
                attribute = new BodyAttribute();
            }
            else if (attributeData.ConstructorArguments.Length == 1 &&
                     SymbolEqualityComparer.Default.Equals(attributeData.ConstructorArguments[0].Type, this.wellKnownSymbols.BodySerializationMethod))
            {
                attribute = new BodyAttribute((BodySerializationMethod)attributeData.ConstructorArguments[0].Value !);
            }

            if (attribute != null)
            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }
Exemplo n.º 2
0
        private Attribute?ParseQueryAttribute(AttributeData attributeData, ISymbol declaringSymbol, DiagnosticReporter diagnosticReporter)
        {
            QueryAttribute?attribute = null;

            if (attributeData.ConstructorArguments.Length == 0)
            {
                attribute = new QueryAttribute();
            }
            else if (attributeData.ConstructorArguments.Length == 1)
            {
                if (attributeData.ConstructorArguments[0].Type?.SpecialType == SpecialType.System_String)
                {
                    attribute = new QueryAttribute((string?)attributeData.ConstructorArguments[0].Value);
                }
                else if (SymbolEqualityComparer.Default.Equals(attributeData.ConstructorArguments[0].Type, this.wellKnownSymbols.QuerySerializationMethod))
                {
                    attribute = new QueryAttribute((QuerySerializationMethod)attributeData.ConstructorArguments[0].Value !);
                }
            }
            else if (attributeData.ConstructorArguments.Length == 2)
            {
                if (attributeData.ConstructorArguments[0].Type?.SpecialType == SpecialType.System_String &&
                    SymbolEqualityComparer.Default.Equals(attributeData.ConstructorArguments[1].Type, this.wellKnownSymbols.QuerySerializationMethod))
                {
                    attribute = new QueryAttribute((string?)attributeData.ConstructorArguments[0].Value, (QuerySerializationMethod)attributeData.ConstructorArguments[1].Value !);
                }
            }

            if (attribute != null)
            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    if (namedArgument.Key == nameof(QueryAttribute.Name) &&
                        namedArgument.Value.Type?.SpecialType == SpecialType.System_String)
                    {
                        attribute.Name = (string?)namedArgument.Value.Value;
                    }
                    else if (namedArgument.Key == nameof(QueryAttribute.SerializationMethod) &&
                             SymbolEqualityComparer.Default.Equals(namedArgument.Value.Type, this.wellKnownSymbols.QuerySerializationMethod))
                    {
                        attribute.SerializationMethod = (QuerySerializationMethod)namedArgument.Value.Value !;
                    }
                    else if (namedArgument.Key == nameof(QueryAttribute.Format) &&
                             namedArgument.Value.Type?.SpecialType == SpecialType.System_String)
                    {
                        attribute.Format = (string?)namedArgument.Value.Value;
                    }
                    else
                    {
                        diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                    }
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }
Exemplo n.º 3
0
        private Attribute?ParseRequestAttributeSubclass(
            AttributeData attributeData,
            ISymbol declaringSymbol,
            DiagnosticReporter diagnosticReporter,
            Func <RequestAttributeBase> parameterlessCtor,
            Func <string, RequestAttributeBase> pathCtor)
        {
            RequestAttributeBase?attribute = null;

            if (attributeData.ConstructorArguments.Length == 0)
            {
                attribute = parameterlessCtor();
            }
            else if (attributeData.ConstructorArguments.Length == 1 &&
                     attributeData.ConstructorArguments[0].Type?.SpecialType == SpecialType.System_String)
            {
                attribute = pathCtor((string)attributeData.ConstructorArguments[0].Value !);
            }

            if (attribute != null)

            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    if (namedArgument.Key == nameof(RequestAttributeBase.Path) &&
                        namedArgument.Value.Type?.SpecialType == SpecialType.System_String)
                    {
                        attribute.Path = (string?)namedArgument.Value.Value;
                    }
                    else
                    {
                        diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                    }
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }
Exemplo n.º 4
0
        private Attribute?ParseSerializationMethodsAttribute(AttributeData attributeData, ISymbol declaringSymbol, DiagnosticReporter diagnosticReporter)
        {
            SerializationMethodsAttribute?attribute = null;

            if (attributeData.ConstructorArguments.Length == 0)
            {
                attribute = new SerializationMethodsAttribute();
            }

            if (attribute != null)
            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    if (namedArgument.Key == nameof(SerializationMethodsAttribute.Body) &&
                        SymbolEqualityComparer.Default.Equals(namedArgument.Value.Type, this.wellKnownSymbols.BodySerializationMethod))
                    {
                        attribute.Body = (BodySerializationMethod)namedArgument.Value.Value !;
                    }
                    else if (namedArgument.Key == nameof(SerializationMethodsAttribute.Query) &&
                             SymbolEqualityComparer.Default.Equals(namedArgument.Value.Type, this.wellKnownSymbols.QuerySerializationMethod))
                    {
                        attribute.Query = (QuerySerializationMethod)namedArgument.Value.Value !;
                    }
                    else if (namedArgument.Key == nameof(SerializationMethodsAttribute.Path) &&
                             SymbolEqualityComparer.Default.Equals(namedArgument.Value.Type, this.wellKnownSymbols.PathSerializationMethod))
                    {
                        attribute.Path = (PathSerializationMethod)namedArgument.Value.Value !;
                    }
                    else
                    {
                        diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                    }
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }
Exemplo n.º 5
0
        private Attribute?ParseHeaderAttribute(AttributeData attributeData, ISymbol declaringSymbol, DiagnosticReporter diagnosticReporter)
        {
            HeaderAttribute?attribute = null;

            if (attributeData.ConstructorArguments.Length == 1 &&
                attributeData.ConstructorArguments[0].Type?.SpecialType == SpecialType.System_String)
            {
                attribute = new HeaderAttribute((string)attributeData.ConstructorArguments[0].Value !);
            }
            else if (attributeData.ConstructorArguments.Length == 2 &&
                     attributeData.ConstructorArguments[0].Type?.SpecialType == SpecialType.System_String &&
                     attributeData.ConstructorArguments[1].Type?.SpecialType == SpecialType.System_String)
            {
                attribute = new HeaderAttribute(
                    (string)attributeData.ConstructorArguments[0].Value !,
                    (string?)attributeData.ConstructorArguments[1].Value);
            }

            if (attribute != null)
            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    if (namedArgument.Key == nameof(HeaderAttribute.Format) &&
                        namedArgument.Value.Type?.SpecialType == SpecialType.System_String)
                    {
                        attribute.Format = (string?)namedArgument.Value.Value;
                    }
                    else
                    {
                        diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                    }
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }
Exemplo n.º 6
0
        private Attribute?ParseRawQueryStringAttribute(AttributeData attributeData, ISymbol declaringSymbol, DiagnosticReporter diagnosticReporter)
        {
            RawQueryStringAttribute?attribute = null;

            if (attributeData.ConstructorArguments.Length == 0)
            {
                attribute = new RawQueryStringAttribute();
            }

            if (attribute != null)
            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }
Exemplo n.º 7
0
        private Attribute?ParseAllowAnyStatusCodeAttribute(AttributeData attributeData, ISymbol declaringSymbol, DiagnosticReporter diagnosticReporter)
        {
            AllowAnyStatusCodeAttribute?attribute = null;

            if (attributeData.ConstructorArguments.Length == 0)
            {
                attribute = new AllowAnyStatusCodeAttribute();
            }
            else if (attributeData.ConstructorArguments.Length == 1 &&
                     attributeData.ConstructorArguments[0].Type?.SpecialType == SpecialType.System_Boolean)
            {
                attribute = new AllowAnyStatusCodeAttribute((bool)attributeData.ConstructorArguments[0].Value !);
            }

            if (attribute != null)
            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    if (namedArgument.Key == nameof(AllowAnyStatusCodeAttribute.AllowAnyStatusCode) &&
                        namedArgument.Value.Type?.SpecialType == SpecialType.System_Boolean)
                    {
                        attribute.AllowAnyStatusCode = (bool)namedArgument.Value.Value !;
                    }
                    else
                    {
                        diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                    }
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }
Exemplo n.º 8
0
        private Attribute?ParseBasePathAttribute(AttributeData attributeData, ISymbol declaringSymbol, DiagnosticReporter diagnosticReporter)
        {
            BasePathAttribute?attribute = null;

            if (attributeData.ConstructorArguments.Length == 1 &&
                attributeData.ConstructorArguments[0].Type?.SpecialType == SpecialType.System_String)
            {
                attribute = new BasePathAttribute((string)attributeData.ConstructorArguments[0].Value !);
            }

            if (attribute != null)
            {
                foreach (var namedArgument in attributeData.NamedArguments)
                {
                    diagnosticReporter.ReportAttributePropertyNotRecognised(attributeData, namedArgument, declaringSymbol);
                }
            }
            else
            {
                diagnosticReporter.ReportAttributeConstructorNotRecognised(attributeData, declaringSymbol);
            }

            return(attribute);
        }