예제 #1
0
        public override MetadataItem VisitNamedType(INamedTypeSymbol symbol)
        {
            var item = DefaultVisit(symbol);

            if (item == null)
            {
                return(null);
            }

            GenerateInheritance(symbol, item);

            item.Type = VisitorHelper.GetMemberTypeFromTypeKind(symbol.TypeKind);
            if (item.Syntax == null)
            {
                item.Syntax = new SyntaxDetail {
                    Content = new SortedList <SyntaxLanguage, string>()
                };
            }
            if (item.Syntax.Content == null)
            {
                item.Syntax.Content = new SortedList <SyntaxLanguage, string>();
            }
            _generator.GenerateSyntax(item.Type, symbol, item.Syntax, this);

            if (symbol.TypeParameters.Length > 0)
            {
                if (item.Syntax.TypeParameters == null)
                {
                    item.Syntax.TypeParameters = new List <ApiParameter>();
                }

                foreach (var p in symbol.TypeParameters)
                {
                    var param = VisitorHelper.GetTypeParameterDescription(p, item, GetTripleSlashCommentParserContext(item, _preserveRawInlineComments));
                    item.Syntax.TypeParameters.Add(param);
                }
            }

            if (symbol.TypeKind == TypeKind.Delegate)
            {
                var typeGenericParameters = symbol.IsGenericType ? symbol.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString;
                AddMethodSyntax(symbol.DelegateInvokeMethod, item, typeGenericParameters, EmptyListOfString);
            }

            _generator.GenerateNamedType(symbol, item, this);

            item.Items = new List <MetadataItem>();
            foreach (var member in symbol.GetMembers().Where(s => !(s is INamedTypeSymbol)))
            {
                var memberItem = member.Accept(this);
                if (memberItem != null)
                {
                    item.Items.Add(memberItem);
                }
            }

            AddReference(symbol);
            return(item);
        }
예제 #2
0
        private MemberType GetMemberTypeFromSymbol(ISymbol symbol)
        {
            switch (symbol.Kind)
            {
            case SymbolKind.Namespace:
                return(MemberType.Namespace);

            case SymbolKind.NamedType:
                INamedTypeSymbol nameTypeSymbol = symbol as INamedTypeSymbol;
                Debug.Assert(nameTypeSymbol != null);
                if (nameTypeSymbol != null)
                {
                    return(VisitorHelper.GetMemberTypeFromTypeKind(nameTypeSymbol.TypeKind));
                }
                else
                {
                    return(MemberType.Default);
                }

            case SymbolKind.Event:
                return(MemberType.Event);

            case SymbolKind.Field:
                return(MemberType.Field);

            case SymbolKind.Property:
                return(MemberType.Property);

            case SymbolKind.Method:
            {
                var methodSymbol = symbol as IMethodSymbol;
                Debug.Assert(methodSymbol != null);
                if (methodSymbol == null)
                {
                    return(MemberType.Default);
                }
                switch (methodSymbol.MethodKind)
                {
                case MethodKind.AnonymousFunction:
                case MethodKind.DelegateInvoke:
                case MethodKind.Destructor:
                case MethodKind.ExplicitInterfaceImplementation:
                case MethodKind.Ordinary:
                case MethodKind.ReducedExtension:
                case MethodKind.DeclareMethod:
                    return(MemberType.Method);

                case MethodKind.BuiltinOperator:
                case MethodKind.UserDefinedOperator:
                case MethodKind.Conversion:
                    return(MemberType.Operator);

                case MethodKind.Constructor:
                case MethodKind.StaticConstructor:
                    return(MemberType.Constructor);

                // ignore: Property's get/set, and event's add/remove/raise
                case MethodKind.PropertyGet:
                case MethodKind.PropertySet:
                case MethodKind.EventAdd:
                case MethodKind.EventRemove:
                case MethodKind.EventRaise:
                default:
                    return(MemberType.Default);
                }
            }

            default:
                return(MemberType.Default);
            }
        }