Ejemplo n.º 1
0
 public static IEnumerable <Attribute> GetAttributes(this ClassDeclarationSyntax classDeclarationSyntax, Type attributeType)
 {
     foreach (var attribute in classDeclarationSyntax.GetAttributesSyntax(attributeType))
     {
         yield return(attribute.GetAttribute(attributeType));
     }
 }
Ejemplo n.º 2
0
        public static ParsedAttribute <T> GetSingleAttribute <T>(this ClassDeclarationSyntax classDeclarationSyntax) where T : Attribute
        {
            var syntax = classDeclarationSyntax.GetAttributesSyntax <T>().ToArray();

            if (syntax.Length != 1)
            {
                return(null);
            }
            return(new ParsedAttribute <T>(syntax.Single()));
        }
Ejemplo n.º 3
0
        public static ParsedAttribute GetSingleAttribute(this ClassDeclarationSyntax classDeclarationSyntax, Type attributeType)
        {
            var syntax = classDeclarationSyntax.GetAttributesSyntax(attributeType).ToArray();

            if (syntax.Length != 1)
            {
                return(null);
            }
            var resultType = typeof(ParsedAttribute <>).MakeGenericType(attributeType);

            return((ParsedAttribute)Activator.CreateInstance(resultType, syntax.Single()));
        }
Ejemplo n.º 4
0
        public static ParsedAttribute[] GetMultipleAttributes(this ClassDeclarationSyntax classDeclarationSyntax, Type attributeType)
        {
            var syntax     = classDeclarationSyntax.GetAttributesSyntax(attributeType).ToArray();
            var resultType = typeof(ParsedAttribute <>).MakeGenericType(attributeType);

            var array = Array.CreateInstance(resultType, syntax.Length);

            for (int index = 0; index < syntax.Length; index++)
            {
                var arrayValue = Activator.CreateInstance(resultType, syntax[index]);
                array.SetValue(arrayValue, index);
            }

            return((ParsedAttribute[])array);
        }
Ejemplo n.º 5
0
        public static ParsedAttribute <T>[] GetMultipleAttributes <T>(this ClassDeclarationSyntax classDeclarationSyntax) where T : Attribute
        {
            var syntax = classDeclarationSyntax.GetAttributesSyntax <T>().ToArray();

            return(syntax.Select(s => new ParsedAttribute <T>(s)).ToArray());
        }
Ejemplo n.º 6
0
 public static IEnumerable <AttributeSyntax> GetAttributesSyntax <T>(this ClassDeclarationSyntax classDeclarationSyntax) where T : Attribute
 {
     return(classDeclarationSyntax.GetAttributesSyntax(typeof(T)));
 }