예제 #1
0
        private IEnumerable <SyntaxToken> ConvertModifiersCore(IEnumerable <SyntaxToken> modifiers, TokenContext context, bool isVariableOrConst = false)
        {
            var contextsWithIdenticalDefaults = new[] { TokenContext.Global, TokenContext.Local, TokenContext.InterfaceOrModule, TokenContext.MemberInInterface };

            if (!contextsWithIdenticalDefaults.Contains(context))
            {
                bool visibility = false;
                foreach (var token in modifiers)
                {
                    if (SyntaxTokenExtensions.IsVbVisibility(token, isVariableOrConst))
                    {
                        visibility = true;
                        break;
                    }
                }
                if (!visibility)
                {
                    yield return(VisualBasicDefaultVisibility(context, isVariableOrConst));
                }
            }
            foreach (var token in modifiers.Where(m => !IgnoreInContext(m, context)).OrderBy(m => SyntaxTokenExtensions.IsKind(m, SyntaxKind.PartialKeyword)))
            {
                var m = ConvertModifier(token, context);
                if (m.HasValue)
                {
                    yield return(m.Value);
                }
            }
            if (context == TokenContext.MemberInModule &&
                !modifiers.Any(a => VisualBasicExtensions.Kind(a) == SyntaxKind.ConstKeyword))
            {
                yield return(SyntaxFactory.Token(Microsoft.CodeAnalysis.CSharp.SyntaxKind.StaticKeyword));
            }
        }
예제 #2
0
        private SyntaxToken?ConvertModifier(SyntaxToken m, TokenContext context = TokenContext.Global)
        {
            SyntaxKind vbSyntaxKind = VisualBasicExtensions.Kind(m);

            switch (vbSyntaxKind)
            {
            case SyntaxKind.DateKeyword:
                return(SyntaxFactory.Identifier("DateTime"));
            }
            var token = vbSyntaxKind.ConvertToken(context);

            return(token == Microsoft.CodeAnalysis.CSharp.SyntaxKind.None ? null : new SyntaxToken?(SyntaxFactory.Token(token)));
        }
예제 #3
0
        private bool IgnoreInContext(SyntaxToken m, TokenContext context)
        {
            switch (VisualBasicExtensions.Kind(m))
            {
            case SyntaxKind.OptionalKeyword:
            case SyntaxKind.ByValKeyword:
            case SyntaxKind.IteratorKeyword:
            case SyntaxKind.DimKeyword:
                return(true);

            default:
                return(false);
            }
        }
 public static bool IsKind(this SyntaxToken token, params Microsoft.CodeAnalysis.VisualBasic.SyntaxKind[] kinds)
 {
     return(kinds.Contains(VisualBasicExtensions.Kind(token)));
 }
 public static bool IsKind(this SyntaxToken token, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind1, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind2, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind3)
 {
     return(VisualBasicExtensions.Kind(token) == kind1 ||
            VisualBasicExtensions.Kind(token) == kind2 ||
            VisualBasicExtensions.Kind(token) == kind3);
 }
 public static bool IsKindOrHasMatchingText(this SyntaxToken token, Microsoft.CodeAnalysis.VisualBasic.SyntaxKind kind)
 {
     return(VisualBasicExtensions.Kind(token) == kind || token.HasMatchingText(kind));
 }