Checks for sequence dependency by Attribute using Roslyn. - CSharp Microsoft.CodeAnalysis

CSharp examples for Microsoft.CodeAnalysis:Roslyn

Description

Checks for sequence dependency by Attribute using Roslyn.

Demo Code


using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis;

public class Main{
        /// <summary>
        /// Checks for sequence dependency by Attribute.
        /// </summary>
        /// <param name="methodSyntax"></param>
        /// <returns></returns>
        public static bool IsSequenceDependent(this MethodDeclarationSyntax methodSyntax)
        {/*from w w w . j  a v  a2 s . c om*/
            if (methodSyntax.AttributeLists.Count > 0)
            { 
                foreach (var attributeSyntax in methodSyntax.AttributeLists.First().Attributes)
                {
                    if (attributeSyntax.Name.ToString() == "VisualScriptingMember")
                    {
                        if (attributeSyntax.ArgumentList == null)
                            return false;

                        return attributeSyntax.ArgumentList.Arguments.First().Expression.Kind() == SyntaxKind.TrueLiteralExpression;
                    }
                }
            }

            return false;
        }
}

Related Tutorials