コード例 #1
0
ファイル: Member.cs プロジェクト: igor-bu/Rubberduck
        public static bool TryParse(string codeLine, out MemberAttribute result)
        {
            var match = Regex.Match(codeLine, AttributeSyntax);

            if (match.Success)
            {
                var name = match.Groups["AttributeName"].Value;

                IEnumerable <string> parameters = null;
                if (match.Groups["Parameters"].Success)
                {
                    parameters = match.Groups["Parameter"].Captures
                                 .Cast <Group>()
                                 .Select(group => group.Value)
                                 .Select(value => value.StartsWith("\"") && value.EndsWith("\"")
                                                                                    ? value.Substring(1, value.Length - 2)
                                                                                    : value)
                                 .ToList();
                }

                result = new MemberAttribute(name, parameters);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }
コード例 #2
0
ファイル: Member.cs プロジェクト: igor-bu/Rubberduck
        public static bool TryParse(string[] body, QualifiedModuleName qualifiedModuleName, out Member result)
        {
            var signature = body.FirstOrDefault(line => _keywords.Any(line.StartsWith));

            if (signature == null)
            {
                result = null;
                return(false);
            }

            signature = signature.Replace("\r", string.Empty);
            body      = body.Select(line => line.Replace("\r", string.Empty)).ToArray();

            var withoutKeyword = signature.Substring((_keywords.First(keyword => signature.StartsWith(keyword))).Length);
            var name           = withoutKeyword.Split(' ')[1]
                                 .Split('(')[0];

            var type       = GetMemberType(signature, withoutKeyword);
            var visibility = GetMemberVisibility(signature);

            var signatureLineIndex = body.ToList().IndexOf(signature);
            var attributes         = MemberAttribute.GetAttributes(body.Take(signatureLineIndex)
                                                                   .Where(line => line.StartsWith("'@")));

            result = new Member(type, qualifiedModuleName.QualifyMemberName(name), signature, body, attributes);
            return(true);
        }
コード例 #3
0
        public static bool HasAttribute(this CodeModule code, string name)
        {
            if (code.CountOfDeclarationLines == 0)
            {
                return(false);
            }
            var moduleAttributes = MemberAttribute.GetAttributes(code.Lines[1, code.CountOfDeclarationLines].Split('\n'));

            return(moduleAttributes.Any(attribute => attribute.Name == name));
        }
コード例 #4
0
ファイル: Member.cs プロジェクト: Mehradzie/Rubberduck
 public static IEnumerable <MemberAttribute> GetAttributes(IEnumerable <string> codeLines)
 {
     foreach (var line in codeLines)
     {
         MemberAttribute attribute;
         if (MemberAttribute.TryParse(line, out attribute))
         {
             yield return(attribute);
         }
     }
 }