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(); }
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); } } }
private static bool IsInAttributeSet(this AttributeSyntax self, HashSet <string> set) { return(self != null && set.Contains(self.GetClassName())); }