private static string GetUniqueName([NotNull] IReferenceExpression referenceExpression, [NotNull] string baseName) { var namingManager = referenceExpression.GetPsiServices().Naming; var policyProvider = namingManager.Policy.GetPolicyProvider(referenceExpression.Language, referenceExpression.GetSourceFile()); var namingRule = policyProvider.GetPolicy(NamedElementKinds.Locals).NamingRule; var name = namingManager.Parsing.Parse(baseName, namingRule, policyProvider); var nameRoot = name.GetRootOrDefault(baseName); var namesCollection = namingManager.Suggestion.CreateEmptyCollection(PluralityKinds.Unknown, CSharpLanguage.Instance, true, policyProvider); namesCollection.Add(nameRoot, new EntryOptions(PluralityKinds.Unknown, SubrootPolicy.Decompose, emphasis: Emphasis.Good)); var suggestionOptions = new SuggestionOptions { DefaultName = baseName, UniqueNameContext = referenceExpression, }; var namesSuggestion = namesCollection.Prepare(NamedElementKinds.Locals, ScopeKind.Common, suggestionOptions); return(namesSuggestion.FirstName()); }