示例#1
0
            private bool TryInitialize(
                GenerateConstructorFromMembersCodeRefactoringProvider service,
                Document document,
                TextSpan textSpan,
                INamedTypeSymbol containingType,
                ImmutableArray <ISymbol> selectedMembers,
                CancellationToken cancellationToken)
            {
                if (!selectedMembers.All(IsWritableInstanceFieldOrProperty))
                {
                    return(false);
                }

                this.SelectedMembers = selectedMembers;
                this.ContainingType  = containingType;
                this.TextSpan        = textSpan;
                if (this.ContainingType == null || this.ContainingType.TypeKind == TypeKind.Interface)
                {
                    return(false);
                }

                this.Parameters          = service.DetermineParameters(selectedMembers);
                this.MatchingConstructor = GetMatchingConstructorBasedOnParameterTypes(this.ContainingType, this.Parameters);
                // We are going to create a new contructor and pass part of the parameters into DelegatedConstructor,
                // so parameters should be compared based on types since we don't want get a type mismatch error after the new constructor is genreated.
                this.DelegatedConstructor = GetDelegatedConstructorBasedOnParameterTypes(this.ContainingType, this.Parameters);
                return(true);
            }
示例#2
0
 public ConstructorDelegatingCodeAction(
     GenerateConstructorFromMembersCodeRefactoringProvider service,
     Document document,
     State state,
     bool addNullChecks)
 {
     _service       = service;
     _document      = document;
     _state         = state;
     _addNullChecks = addNullChecks;
 }
 public GenerateConstructorWithDialogCodeAction(
     GenerateConstructorFromMembersCodeRefactoringProvider service,
     Document document, TextSpan textSpan,
     INamedTypeSymbol containingType,
     ImmutableArray <ISymbol> viableMembers,
     ImmutableArray <PickMembersOption> pickMembersOptions)
 {
     _service            = service;
     _document           = document;
     _textSpan           = textSpan;
     _containingType     = containingType;
     _viableMembers      = viableMembers;
     _pickMembersOptions = pickMembersOptions;
 }
示例#4
0
            public static State TryGenerate(
                GenerateConstructorFromMembersCodeRefactoringProvider service,
                Document document,
                TextSpan textSpan,
                INamedTypeSymbol containingType,
                ImmutableArray <ISymbol> selectedMembers,
                CancellationToken cancellationToken)
            {
                var state = new State();

                if (!state.TryInitialize(service, document, textSpan, containingType, selectedMembers, cancellationToken))
                {
                    return(null);
                }

                return(state);
            }