private VariableStyle GetVariableStyle( Dictionary <ISymbol, List <SyntaxToken> > symbolMap, ISymbol symbol, SemanticModel model, ITypeSymbol type, bool captured, bool dataFlowIn, bool dataFlowOut, bool alwaysAssigned, bool variableDeclared, bool readInside, bool writtenInside, bool readOutside, bool writtenOutside, bool unsafeAddressTaken) { Contract.ThrowIfNull(model); Contract.ThrowIfNull(type); var style = ExtractMethodMatrix.GetVariableStyle(captured, dataFlowIn, dataFlowOut, alwaysAssigned, variableDeclared, readInside, writtenInside, readOutside, writtenOutside, unsafeAddressTaken); if (SelectionContainsOnlyIdentifierWithSameType(type)) { return(style); } if (UserDefinedValueType(model.Compilation, type) && !this.SelectionResult.DontPutOutOrRefOnStruct) { return(AlwaysReturn(style)); } // for captured variable, never try to move the decl into extracted method if (captured && (style == VariableStyle.MoveIn)) { return(VariableStyle.Out); } // check special value type cases if (type.IsValueType && !IsWrittenInsideForFrameworkValueType(symbolMap, model, symbol, writtenInside)) { return(style); } // don't blindly always return. make sure there is a write inside of the selection if (this.SelectionResult.AllowMovingDeclaration || !writtenInside) { return(style); } return(AlwaysReturn(style)); }
private bool TryGetVariableStyle( bool bestEffort, Dictionary <ISymbol, List <SyntaxToken> > symbolMap, ISymbol symbol, SemanticModel model, ITypeSymbol type, bool captured, bool dataFlowIn, bool dataFlowOut, bool alwaysAssigned, bool variableDeclared, bool readInside, bool writtenInside, bool readOutside, bool writtenOutside, bool unsafeAddressTaken, out VariableStyle variableStyle) { Contract.ThrowIfNull(model); Contract.ThrowIfNull(type); if (!ExtractMethodMatrix.TryGetVariableStyle( bestEffort, dataFlowIn, dataFlowOut, alwaysAssigned, variableDeclared, readInside, writtenInside, readOutside, writtenOutside, unsafeAddressTaken, out variableStyle)) { Contract.ThrowIfTrue(bestEffort, "Should never fail if bestEffort is true"); return(false); } if (SelectionContainsOnlyIdentifierWithSameType(type)) { return(true); } if (UserDefinedValueType(model.Compilation, type) && !SelectionResult.DontPutOutOrRefOnStruct) { variableStyle = AlwaysReturn(variableStyle); return(true); } // for captured variable, never try to move the decl into extracted method if (captured && variableStyle == VariableStyle.MoveIn) { variableStyle = VariableStyle.Out; return(true); } // check special value type cases if (type.IsValueType && !IsWrittenInsideForFrameworkValueType(symbolMap, model, symbol, writtenInside)) { return(true); } // don't blindly always return. make sure there is a write inside of the selection if (!writtenInside) { return(true); } variableStyle = AlwaysReturn(variableStyle); return(true); }