Exemplo n.º 1
0
        public override IReadOnlyList <IParsedBindExpression> Create(
            ExpressionStatementSyntax expressionNode,
            List <Tuple <InvocationExpressionSyntax, IMethodSymbol> > invocationSymbols
            )
        {
            if (expressionNode is null)
            {
                throw new ArgumentNullException(nameof(expressionNode));
            }

            if (invocationSymbols is null)
            {
                throw new ArgumentNullException(nameof(invocationSymbols));
            }

            var result = new List <IParsedBindExpression>();

            var scope = DetermineScope(invocationSymbols);

            switch (scope)
            {
            case BindScopeEnum.Transient:
            case BindScopeEnum.Singleton:
            case BindScopeEnum.Custom:
                var to = GetTo(invocationSymbols);

                var fromTypesProvider = FromTypesProviderFactory.CreateFromTypesProvider(invocationSymbols);
                var from = fromTypesProvider.GetBindFromTypes(to);
                //var from = invocationSymbols.First(
                //    s => s.Item2.ContainingType.ToGlobalDisplayString() == typeof(DefaultCluster).ToGlobalDisplayString() && s.Item2.Name == DefaultCluster.BindMethodName
                //    );


                result.Add(
                    new STCParsedBindExpression(
                        _typeInfoContainer,
                        _extractor,
                        _constructorArgumentDetector,
                        expressionNode,
                        invocationSymbols,
                        from,
                        to,
                        scope,
                        false
                        )
                    );
                break;

            case BindScopeEnum.Constant:
                result.Add(
                    new ConstantParsedBindExpression(
                        _semanticModel,
                        expressionNode,
                        invocationSymbols
                        )
                    );
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(result);
        }
Exemplo n.º 2
0
        public ConventionalBindingSyntaxParser(
            ExpressionStatementSyntax expressionNode,
            List <Tuple <InvocationExpressionSyntax, IMethodSymbol> > invocationSymbols
            )
        {
            if (expressionNode is null)
            {
                throw new ArgumentNullException(nameof(expressionNode));
            }

            if (invocationSymbols is null)
            {
                throw new ArgumentNullException(nameof(invocationSymbols));
            }

            ExpressionNode    = expressionNode;
            InvocationSymbols = invocationSymbols;

            ScanInList = invocationSymbols
                         .Where(
                s => s.Item2.ContainingType.ToGlobalDisplayString() == typeof(DefaultCluster).ToGlobalDisplayString() && s.Item2.Name == DefaultCluster.ScanInAssembliesWithMethodName
                )
                         .SelectMany(s => s.Item2.TypeArguments)
                         .ToList()
            ;

            var selectWithSet = new List <ITypeSymbol>();

            selectWithSet.AddRange(
                invocationSymbols
                .Where(
                    s => s.Item2.ContainingType.ToGlobalDisplayString().In(typeof(IConventionalBinding).ToGlobalDisplayString(), typeof(IConventionalBinding2).ToGlobalDisplayString()) && s.Item2.Name == nameof(IConventionalBinding.SelectAllWith)
                    )
                .SelectMany(s => s.Item2.TypeArguments)
                );
            selectWithSet.AddRange(
                invocationSymbols
                .Where(
                    s => s.Item2.ContainingType.ToGlobalDisplayString().In(typeof(IConventionalBinding).ToGlobalDisplayString(), typeof(IConventionalBinding2).ToGlobalDisplayString()) && s.Item2.Name == nameof(IConventionalBinding.SelectAllWithOpenGeneric)
                    )
                .SelectMany(s => s.Item2.TypeArguments)
                .Select(ta => ta as INamedTypeSymbol)
                .Where(nta => nta != null)
                .Select(nta => nta !.OriginalDefinition)
                );
            SelectWithSet = selectWithSet;

            var excludeWithSet = new List <ITypeSymbol>();

            excludeWithSet.AddRange(
                invocationSymbols
                .Where(
                    s => s.Item2.ContainingType.ToGlobalDisplayString().In(typeof(IConventionalBinding).ToGlobalDisplayString(), typeof(IConventionalBinding2).ToGlobalDisplayString()) && s.Item2.Name == nameof(IConventionalBinding2.ExcludeAllWith)
                    )
                .SelectMany(s => s.Item2.TypeArguments)
                );
            excludeWithSet.AddRange(
                invocationSymbols
                .Where(
                    s => s.Item2.ContainingType.ToGlobalDisplayString().In(typeof(IConventionalBinding).ToGlobalDisplayString(), typeof(IConventionalBinding2).ToGlobalDisplayString()) && s.Item2.Name == nameof(IConventionalBinding2.ExcludeAllWithOpenGeneric)
                    )
                .SelectMany(s => s.Item2.TypeArguments)
                .Select(ta => ta as INamedTypeSymbol)
                .Where(nta => nta != null)
                .Select(nta => nta !.OriginalDefinition)
                );
            ExcludeWithSet = excludeWithSet;

            FromTypesProvider = FromTypesProviderFactory.CreateFromTypesProvider(invocationSymbols);
        }