Ejemplo n.º 1
0
            private bool DetermineNamespaceOrTypeToGenerateIn(
                TService service,
                SemanticModel semanticModel,
                TExpressionSyntax leftSide,
                CancellationToken cancellationToken)
            {
                var leftSideInfo = semanticModel.GetSymbolInfo(leftSide, cancellationToken);

                if (leftSideInfo.Symbol != null)
                {
                    var symbol = leftSideInfo.Symbol;

                    if (symbol is INamespaceSymbol)
                    {
                        this.NamespaceToGenerateInOpt = symbol.ToNameDisplayString();
                        return(true);
                    }
                    else if (symbol is INamedTypeSymbol)
                    {
                        // TODO: Code coverage
                        this.TypeToGenerateInOpt = (INamedTypeSymbol)symbol.OriginalDefinition;
                        return(true);
                    }

                    // We bound to something other than a namespace or named type.  Can't generate a
                    // type inside this.
                    return(false);
                }
                else
                {
                    // If it's a dotted name, then perhaps it's a namespace.  i.e. the user wrote
                    // "new Foo.Bar.Baz()".  In this case we want to generate a namespace for
                    // "Foo.Bar".
                    IList <string> nameParts;
                    if (service.TryGetNameParts(leftSide, out nameParts))
                    {
                        this.NamespaceToGenerateInOpt = string.Join(".", nameParts);
                        return(true);
                    }
                }

                return(false);
            }