Exemplo n.º 1
0
        private static void RegisterForOne(RefactoringContext context, InjectParameter parameter, ConstructorDeclarationSyntax ctor)
        {
            if (!Helpers.NeedInject(parameter, ctor))
            {
                return;
            }

            context.RegisterAsync(new InjectFromConstructor(parameter, ctor));
        }
Exemplo n.º 2
0
        public InjectFromConstructor(InjectParameter parameter, ConstructorDeclarationSyntax ctor, int?ctorNo = null)
        {
            Requires(parameter != null);
            Requires(ctor != null);

            _parameter = parameter;
            _ctor      = ctor;
            _ctorNo    = ctorNo;
        }
Exemplo n.º 3
0
        public static bool NeedInject(InjectParameter parameter, ConstructorDeclarationSyntax constructor)
        {
            Contract.Requires(parameter != null);
            Contract.Requires(constructor != null);

            var fieldName  = parameter.Name;
            var assigments = constructor.Body?.DescendantNodes().OfType <AssignmentExpressionSyntax>().ToList();

            foreach (var assigment in assigments.WhileOk())
            {
                if (assigment.GetAssigneeName(allowThisAccess: true) == fieldName)
                {
                    return(false);
                }
            }

            return(!CancellationTokenExtensions.IsCancellationRequested());
        }
Exemplo n.º 4
0
        private static void RegisterForAll(RefactoringContext context, InjectParameter parameter, IEnumerable <ConstructorDeclarationSyntax> ctors)
        {
            context.RegisterAsync(new InjectFromAllConstructors(parameter));

            var index = 1;

            foreach (var ctor in ctors.WhileOk())
            {
                if (!Helpers.NeedInject(parameter, ctor))
                {
                    continue;
                }

                context.RegisterAsync(new InjectFromConstructor(parameter, ctor, index));

                index++;
            }
        }
Exemplo n.º 5
0
 public CreateConstructor(InjectParameter parameter)
 {
     Requires(parameter != null);
     _parameter = parameter;
 }
Exemplo n.º 6
0
 public InjectFromAllConstructors(InjectParameter parameter)
 {
     Requires(parameter != null);
     _parameter = parameter;
 }