Пример #1
0
        /// <summary>
        /// Looks for external types in the current compilation
        /// </summary>
        private void FindExternalTypes()
        {
            INamedTypeSymbol exterTypeExtrAttr = Compilation.GetTypeByMetadataName(typeof(ScriptObjectsAttribute).FullName);

            foreach (AttributeData attrData in Compilation.Assembly.GetAttributes())
            {
                if (attrData.AttributeClass.Equals(exterTypeExtrAttr))
                {
                    string targetPath = "";
                    for (int i = 0; i < attrData.ConstructorArguments.Length; i++)
                    {
                        TypedConstant typedConstant = attrData.ConstructorArguments[i];
                        if (typedConstant.Kind == TypedConstantKind.Primitive)
                        {
                            targetPath = typedConstant.Value as string;
                        }
                        else
                        {
                            foreach (TypedConstant oneTypeArg in typedConstant.Values)
                            {
                                INamedTypeSymbol type = oneTypeArg.Value as INamedTypeSymbol;

                                ParseContext context   = new ParseContext(Compilation, GetDocumentationProvider(type));
                                INamedType   namedType = RoslynType.CreateNamedType(type, context);
                                _visitor.VisitExternalType(namedType, targetPath);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Visits enums and adds script enums to the package
        /// </summary>
        /// <param name="node">The node</param>
        public override void VisitEnumDeclaration(EnumDeclarationSyntax node)
        {
            INamedTypeSymbol namedType       = Compilation.GetSemanticModel(node.SyntaxTree).GetDeclaredSymbol(node);
            RoslynNamedType  namedTypeResult = RoslynType.CreateNamedType(
                namedType,
                new ParseContext(Compilation, new SourceCommentsDocumentationProvider(), _options)
                );

            _visitor.Visit(namedTypeResult);
        }
Пример #3
0
        /// <summary>
        /// Trys to add a type declaration node to the extract depending on whether it has
        /// the <see cref="ScriptObjectAttribute"/>
        /// </summary>
        /// <param name="node">The type declaration node</param>
        private void TryAddTypeDeclaration(TypeDeclarationSyntax node)
        {
            INamedTypeSymbol namedType = Compilation.GetSemanticModel(node.SyntaxTree).GetDeclaredSymbol(node);

            RoslynNamedType namedTypeResult = RoslynType.CreateNamedType(
                namedType,
                new ParseContext(Compilation, new SourceCommentsDocumentationProvider())
                );

            _visitor.Visit(namedTypeResult);
        }
        /// <summary>
        /// Gets the return type for the given method
        /// </summary>
        /// <param name="method">The method symbol</param>
        /// <returns>The calculated return type, or null if one is not found</returns>
        public IType GetReturnType(IMethodSymbol method)
        {
            _model = _context.Compilation.GetSemanticModel(method.DeclaringSyntaxReferences[0].SyntaxTree);

            // TODO: this only gets the first syntax, which is usually valid, but could be wrong for partial methods
            SyntaxNode node = method.DeclaringSyntaxReferences.FirstOrDefault().GetSyntax();

            Visit(node);

            if (_retType == null)
            {
                _retType = RoslynType.CreateType(method.ReturnType, _context);
            }

            return(_retType);
        }
        /// <summary>
        /// Gets the return type for the given method
        /// </summary>
        /// <param name="method">The method symbol</param>
        /// <returns>The calculated return type, or null if one is not found</returns>
        public IType GetReturnType(IMethodSymbol method)
        {
            _model          = _context.Compilation.GetSemanticModel(method.DeclaringSyntaxReferences[0].SyntaxTree);
            _handlerFactory = new ReturnSyntaxNodeHandlerFactory(_model, _context, method);

            // This only gets the first syntax, which is usually valid, but could be wrong for partial methods
            SyntaxNode node = method.DeclaringSyntaxReferences.FirstOrDefault().GetSyntax();

            Visit(node);

            IType foundType = _candidates.LastOrDefault();              // Maybe select best type? OR merge types possibly.  Probably a rare use case.

            if (foundType == null)
            {
                foundType = RoslynType.CreateType(method.ReturnType, _context);
            }

            return(foundType);
        }
Пример #6
0
        /// <summary>
        /// Looks for external types in the current compilation
        /// </summary>
        private void FindExternalTypes()
        {
            INamedTypeSymbol exterTypeExtrAttr = Compilation.GetTypeByMetadataName(typeof(ExternalScriptObjectAttribute).FullName);

            foreach (AttributeData attrData in Compilation.Assembly.GetAttributes())
            {
                if (attrData.AttributeClass.Equals(exterTypeExtrAttr))
                {
                    TypedConstant typeParamsArg = attrData.ConstructorArguments[0];

                    foreach (TypedConstant oneTypeArg in typeParamsArg.Values)
                    {
                        INamedTypeSymbol type = oneTypeArg.Value as INamedTypeSymbol;

                        ParseContext context   = new ParseContext(Compilation, GetDocumentationProvider(type), _options);
                        INamedType   namedType = RoslynType.CreateNamedType(type, context);
                        _visitor.VisitExternalType(namedType);
                    }
                }
            }
        }
 private IType FromSymbol(ITypeSymbol symbol) => RoslynType.CreateType(symbol, _context);
Пример #8
0
 /// <inheritdoc/>
 public override IType GetReturnType(ParseContext context, ITypeSymbol currentType, IMethodSymbol method)
 {
     return(RoslynType.CreateType(currentType, context));
 }
 protected IType FromSymbol(ITypeSymbol symbol) => RoslynType.CreateType(symbol, HandlerContext.Context);