Esempio n. 1
0
        IEnumerable <BasedOnRegistrationBase> IBasedOnPattern.GetBasedOnRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                ITreeNode element = match.GetMatchedElement("argument");
                if (element != null)
                {
                    foreach (var whereArgumentPattern in whereArgumentPatterns)
                    {
                        var registrations = whereArgumentPattern.GetBasedOnRegistrations(element).ToArray();
                        if (!registrations.Any())
                        {
                            // try with the root element.
                            registrations = whereArgumentPattern.GetBasedOnRegistrations(registrationRootElement).ToArray();
                        }

                        foreach (var registration in registrations)
                        {
                            yield return(registration);
                        }
                    }
                }
            }
        }
        protected override INamespace GetNamespaceElement(IStructuralMatchResult match, out bool includeSubnamespaces)
        {
            includeSubnamespaces = false;
            var argument = match.GetMatchedElement("subnamespace") as ICSharpArgument;
            if (argument != null)
            {
                if (argument.Value.ConstantValue != null &&
                    argument.Value.ConstantValue.IsBoolean())
                {
                    includeSubnamespaces = Convert.ToBoolean(argument.Value.ConstantValue.Value);
                }
            }

            var declaredType = match.GetMatchedType("type") as IDeclaredType;
            if (declaredType != null)
            {
                ITypeElement typeElement = declaredType.GetTypeElement();
                if (typeElement != null)
                {
                    return typeElement.GetContainingNamespace();
                }
            }

            return null;
        }
Esempio n. 3
0
        public override IEnumerable <IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var argument = match.GetMatchedElement(ElementName) as ICSharpArgument;
                if (argument == null)
                {
                    yield break;
                }

                // match typeof() expressions
                var typeOfExpression = argument.Value as ITypeofExpression;
                if (typeOfExpression != null)
                {
                    var typeElement = ((IDeclaredType)typeOfExpression.ArgumentType).GetTypeElement();
                    if (typeElement == null) // can happen if the typeof() expression is empty
                    {
                        yield break;
                    }

                    yield return(new ComponentRegistration(registrationRootElement, typeElement));
                }
            }
        }
Esempio n. 4
0
        protected override IEnumerable <BasedOnRegistrationBase> DoCreateRegistrations(ITreeNode registrationRootElement, IStructuralMatchResult match)
        {
            var argument = match.GetMatchedElement("argument") as ICSharpArgument;

            if (argument == null)
            {
                yield break;
            }

            var typeofExpression = argument.Value as ITypeofExpression;

            if (typeofExpression != null)
            {
                var declaredType = typeofExpression.ArgumentType as IDeclaredType;
                if (declaredType != null)
                {
                    ITypeElement typeElement = declaredType.GetTypeElement();
                    if (typeElement != null)
                    {
                        // todo possible bug: same as in the generic variant. Currently works the same as As<T>.
                        yield return(new ElementBasedOnRegistration(registrationRootElement, typeElement));
                    }
                }
            }
        }
Esempio n. 5
0
        protected override INamespace GetNamespaceElement(IStructuralMatchResult match, out bool includeSubnamespaces)
        {
            includeSubnamespaces = true;

            var argument = (ICSharpArgument)match.GetMatchedElement("argument");
            if (argument != null)
            {
                return PsiExtensions.GetNamespaceDeclaration(argument.Value);
            }

            return null;
        }
Esempio n. 6
0
 protected override IEnumerable<FilteredRegistrationBase> DoCreateRegistrations(ITreeNode registrationRootElement, IStructuralMatchResult match)
 {
     var argument = match.GetMatchedElement("argument") as ICSharpArgument;
     if (argument != null)
     {
         INamespace @namespace = PsiExtensions.GetNamespaceDeclaration(argument.Value);
         if (@namespace != null)
         {
             yield return new InNamespaceRegistration(registrationRootElement, @namespace, true);
         }
     }
 }
Esempio n. 7
0
        protected override IEnumerable <FilteredRegistrationBase> DoCreateRegistrations(ITreeNode registrationRootElement, IStructuralMatchResult match)
        {
            var argument = match.GetMatchedElement("argument") as ICSharpArgument;

            if (argument != null)
            {
                INamespace @namespace = ReSharper.Domain.Utils.PsiExtensions.GetNamespaceDeclaration(argument.Value);
                if (@namespace != null)
                {
                    yield return(new InNamespaceRegistration(registrationRootElement, @namespace, true));
                }
            }
        }
Esempio n. 8
0
        protected override INamespace GetNamespaceElement(IStructuralMatchResult match, out bool includeSubnamespaces)
        {
            includeSubnamespaces = true;

            var argument = (ICSharpArgument)match.GetMatchedElement("argument");

            if (argument != null)
            {
                return(PsiExtensions.GetNamespaceDeclaration(argument.Value));
            }

            return(null);
        }
        public override IEnumerable <IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var expression = match.GetMatchedElement <IObjectCreationExpression>("expression");
                if (expression != null && expression.TypeReference != null)
                {
                    IResolveResult resolveResult = expression.TypeReference.Resolve().Result;
                    var            @class        = resolveResult.DeclaredElement as IClass;
                    if (@class != null)
                    {
                        yield return(new ComponentRegistration(registrationRootElement, @class, @class));
                    }
                }
            }
        }
Esempio n. 10
0
        protected override IEnumerable <IComponentRegistration> DoCreateRegistrations(ITreeNode parentElement)
        {
            IStructuralMatchResult match = Match(parentElement);

            if (match.Matched)
            {
                var argument = match.GetMatchedElement(ElementName) as ICSharpArgument;
                if (argument == null)
                {
                    yield break;
                }

                // match typeof() expressions
                var typeOfExpression = argument.Value as ITypeofExpression;
                if (typeOfExpression != null)
                {
                    var typeElement = (IDeclaredType)typeOfExpression.ArgumentType;

                    yield return(new ComponentRegistration(parentElement, typeElement.GetTypeElement()));
                }
            }
        }
Esempio n. 11
0
        protected override IEnumerable<FilteredRegistrationBase> DoCreateRegistrations(ITreeNode registrationRootElement, IStructuralMatchResult match)
        {
            var argument = match.GetMatchedElement("argument") as ICSharpArgument;
            if (argument != null)
            {
                var typeOfExpression = argument.Value as ITypeofExpression;
                if (typeOfExpression != null)
                {
                    var argumentType = typeOfExpression.ArgumentType as IDeclaredType;
                    if (argumentType != null)
                    {
                        var typeElement = argumentType.GetTypeElement();
                        if (typeElement == null)
                        {
                            yield break;
                        }

                        yield return new ClosingTypesRegistration(registrationRootElement, typeElement);
                    }
                }
            }
        }
Esempio n. 12
0
        protected override IEnumerable <FilteredRegistrationBase> DoCreateRegistrations(ITreeNode registrationRootElement, IStructuralMatchResult match)
        {
            var argument = match.GetMatchedElement("argument") as ICSharpArgument;

            if (argument != null)
            {
                var typeOfExpression = argument.Value as ITypeofExpression;
                if (typeOfExpression != null)
                {
                    var argumentType = typeOfExpression.ArgumentType as IDeclaredType;
                    if (argumentType != null)
                    {
                        var typeElement = argumentType.GetTypeElement();
                        if (typeElement == null)
                        {
                            yield break;
                        }

                        yield return(new ClosingTypesRegistration(registrationRootElement, typeElement));
                    }
                }
            }
        }
Esempio n. 13
0
        public override IEnumerable <IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var invocationExpression = match.GetMatchedElement("bind") as IInvocationExpression;
                if (invocationExpression == null)
                {
                    yield break;
                }

                IDeclaredType declaredType = GetDeclaredType(invocationExpression);
                if (declaredType != null)
                {
                    ITypeElement typeElement = declaredType.GetTypeElement();
                    if (typeElement != null)
                    {
                        yield return(new ComponentRegistration(registrationRootElement, typeElement));
                    }
                }
            }
        }
        protected override IEnumerable<FilteredRegistrationBase> DoCreateRegistrations(ITreeNode registrationRootElement, IStructuralMatchResult match)
        {
            var argument = match.GetMatchedElement("argument") as ICSharpArgument;
            if (argument == null)
            {
                yield break;
            }

            var typeofExpression = argument.Value as ITypeofExpression;
            if (typeofExpression != null)
            {
                var declaredType = typeofExpression.ArgumentType as IDeclaredType;
                if (declaredType != null)
                {
                    ITypeElement typeElement = declaredType.GetTypeElement();
                    if (typeElement != null)
                    {
                        // todo possible bug: same as in the generic variant. Currently works the same as As<T>.
                        yield return new ServiceRegistration(registrationRootElement, typeElement);
                    }
                }
            }
        }
        protected override IModule GetTargetModule(IStructuralMatchResult match)
        {
            var argument = (ICSharpArgument)match.GetMatchedElement("argument");

            return ModuleExtractor.GetTargetModule(argument.Value);
        }
Esempio n. 16
0
        protected override IModule GetTargetModule(IStructuralMatchResult match)
        {
            var argument = (ICSharpArgument)match.GetMatchedElement("assemblyName");

            return(ModuleExtractor.GetTargetModule(argument.Value));
        }