Ejemplo n.º 1
0
        // 以下はプロパティではなく別扱いみたいです。本ツール内では、今のところプロパティ扱いします。
        // public object this[int index] { get; set; }
        public override void VisitIndexerDeclaration(IndexerDeclarationSyntax node)
        {
            var startLength     = node.Span.Start;
            var endLength       = node.Span.End;
            var parentNamespace = GetNamespace(DefineKinds.Indexer, startLength, endLength);

            var defineType = node.ChildNodes().FirstOrDefault().ToString();
            var defineName = node.ChildTokens().FirstOrDefault(x => x.Kind() == SyntaxKind.ThisKeyword).ToString();

            var methodArguments = new List <MethodArgument>();

            if (node.ChildNodes().OfType <BracketedParameterListSyntax>().Any())
            {
                if (node.ChildNodes().OfType <BracketedParameterListSyntax>().FirstOrDefault().ChildNodes().Any())
                {
                    var listNode = node.ChildNodes().OfType <BracketedParameterListSyntax>().FirstOrDefault();
                    methodArguments = GetIndexerArguments(listNode);
                }
            }

            UserDefinitions.Add(new UserDefinition
            {
                DefineKinds     = DefineKinds.Indexer,
                Namespace       = parentNamespace,
                DefineName      = defineName,
                DefineFullName  = $"{parentNamespace}.{defineName}",
                MethodArguments = methodArguments,
                ReturnType      = RemoveNamespace(defineType),
                SourceFile      = SourceFile,
                StartLength     = startLength,
                EndLength       = endLength,
            });
            base.VisitIndexerDeclaration(node);
        }