Reporter | Lilia Shamsutdinova (Lilia.Shamsutdinova) |
---|---|
Created | Apr 17, 2018 11:22:40 AM |
Updated | Apr 17, 2018 11:22:40 AM |
Subsystem | Refactorings |
Assignee | Alisa Afonina (alisa.afonina) |
Priority | Show-stopper |
State | Submitted |
Type | Bug |
Fix version | 2018.2 |
Affected versions | 2018.2 |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
JetBrains ReSharper Ultimate 182.0.20180416.132916-eap00d.
internal class Book
{
public string Author { get; set; }
public string Title { get; set; }
}
public class ConvertAnonymousToNamedType
{
private string Test(List<Book> books)
{
var bookList = from book in books
select new { book.Author, book.Title };
var bookListNotApplied = from book in books
select new { book.Author, title = new { book.Title } };
var bookNew = bookList.ToList().FirstOrDefault(book => book.Author == "King");
return bookNew?.Author;
}
}
- Invoke Refactor This -> Replace Anonymous Type With Named Class on
new { book.Author, book.Title }
. - Set "int" as Name; "Solution" as Scope; "Top Level" as Location; "Writable auto properties" as How to generate; check both Generate checkboxes (see screenshot).
- Click Next.
Actual result:
Uncompilable code is generated.
public class @int
{
public string Author { get; set; }
public string Title { get; set; }
public override string ToString()
{
return $"{{ Author = {Author}, Title = {Title} }}";
}
public override bool Equals(object value)
{
var type = value as int; // <------------------------------------- Should be @int
return (type != null) && EqualityComparer<string>.Default.Equals(type.Author, Author) && EqualityComparer<string>.Default.Equals(type.Title, Title);
}
public override int GetHashCode()
{
int num = 0x7a2f0b42;
num = (-1521134295 * num) + EqualityComparer<string>.Default.GetHashCode(Author);
return (-1521134295 * num) + EqualityComparer<string>.Default.GetHashCode(Title);
}
}
Expected result:
Code is compilable.