Exemple #1
0
 public RequestAttribute(AttributeSyntax attributeSyntax)
 {
     this.ClassName = attributeSyntax.GetClassName();
     this.Arguments = attributeSyntax.ArgumentList?
                      .Arguments
                      .Select(x => SyntaxFactory.Argument(x.Expression))
                      .ToArray();
     this.ArgumentCount         = (this.Arguments?.Length).GetValueOrDefault();
     this.AttachedParameterName = attributeSyntax.GetParameterName();
     this.Type = attributeSyntax.GetRequestAttributeType();
 }
Exemple #2
0
        public static RequestAttributeType GetRequestAttributeType(this AttributeSyntax self)
        {
            string className = self.GetClassName();

            if (self.IsInAttributeSet(HttpMethodAttributeNames))
            {
                return(RequestAttributeType.HttpMethod);
            }
            else if (self.IsInAttributeSet(FormatterAttributeNames))
            {
                return(RequestAttributeType.Formatter);
            }
            else
            {
                string fullClassName = className + (nameof(Attribute));
                switch (fullClassName)
                {
                case nameof(NameAttribute):
                    return(RequestAttributeType.Name);

                case nameof(UriTemplatePrefixAttribute):
                    return(RequestAttributeType.UriTemplatePrefix);

                case nameof(UriTemplateSuffixAttribute):
                    return(RequestAttributeType.UriTemplateSuffix);

                case nameof(HeaderAttribute):
                    return(RequestAttributeType.Header);

                case nameof(HeaderValueAttribute):
                    return(RequestAttributeType.HeaderValue);

                case nameof(ContentAttribute):
                    return(RequestAttributeType.Content);

                case nameof(FormUrlEncodedContentAttribute):
                    return(RequestAttributeType.FormUrlEncodedContent);

                default:
                    return(default);
                }
            }
        }
Exemple #3
0
 private static bool IsInAttributeSet(this AttributeSyntax self, HashSet <string> set)
 {
     return(self != null && set.Contains(self.GetClassName()));
 }