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 = service.GetMatchingConstructor(this.ContainingType, this.Parameters); this.DelegatedConstructor = service.GetDelegatedConstructor(this.ContainingType, this.Parameters); return(true); }
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); }
private async Task <bool> TryInitializeAsync( GenerateConstructorFromMembersCodeRefactoringProvider service, Document document, TextSpan textSpan, INamedTypeSymbol containingType, ImmutableArray <ISymbol> selectedMembers, CancellationToken cancellationToken) { if (!selectedMembers.All(IsWritableInstanceFieldOrProperty)) { return(false); } SelectedMembers = selectedMembers; ContainingType = containingType; TextSpan = textSpan; if (ContainingType == null || ContainingType.TypeKind == TypeKind.Interface) { return(false); } var rules = await document.GetNamingRulesAsync(FallbackNamingRules.RefactoringMatchLookupRules, cancellationToken).ConfigureAwait(false); Parameters = service.DetermineParameters(selectedMembers, rules); MatchingConstructor = GetMatchingConstructorBasedOnParameterTypes(ContainingType, 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. DelegatedConstructor = GetDelegatedConstructorBasedOnParameterTypes(ContainingType, Parameters); return(true); }
public FieldDelegatingCodeAction( GenerateConstructorFromMembersCodeRefactoringProvider service, Document document, State state) { _service = service; _document = document; _state = state; }
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) { _service = service; _document = document; _textSpan = textSpan; _containingType = containingType; _viableMembers = viableMembers; }
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); }