2017-04-04 9 views
9

W Visual Studio 2017, w "szybkich działań i refaktoryzacji" menu, po kliknięciu "zaimplementować interfejs", otrzymuję implementacje używające nowsze funkcje C# tak:Czy narzędzie "Implementacja interfejsu" programu Visual Studio 2017 generuje kod C# 5?

public int ConnectionTimeout => throw new NotImplementedException(); 

Problem polega na tym, że moja firma używa C# 5, więc nie możemy użyć tej nowszej składni. Wiem, że starsze wersje programu Visual Studio wygenerowałyby ten kod zamiast:

public int ConnectionTimeout { get { throw new NotImplementedException(); } } 

Czy istnieje sposób, aby to zrobić w Visual Studio 2017? Ustawiłem mój projekt do kompilacji przy użyciu C# 5.

Edycja: Zauważyłem, że generator kodu jest niespójny. Jeśli interfejs ma element bool, który ma tylko funkcję pobierającą, używa starej składni. W przeciwnym razie używa nowej składni. To sprawia, że ​​myślę, że nie mam szczęścia.

private interface myint 
{ 
    bool bool1 { get; } 
    bool bool2 { get; set; } 
    bool bool3 { set; } 

    int int1 { get; } 
    int int2 { get; set; } 
    int int3 { set; } 

    string string1 { get; } 
    string string2 { get; set; } 
    string string3 { set; } 
} 

private class myclass : myint //I clicked "Implement Interface" on this 
{ 
    public bool bool1 
    { 
     get 
     { 
      throw new NotImplementedException(); 
     } 
    } 

    public bool bool2 { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } 
    public bool bool3 { set => throw new NotImplementedException(); } 

    public int int1 => throw new NotImplementedException(); 

    public int int2 { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } 
    public int int3 { set => throw new NotImplementedException(); } 

    public string string1 => throw new NotImplementedException(); 

    public string string2 { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } 
    public string string3 { set => throw new NotImplementedException(); } 
} 
+0

na właściwości projektu, na karcie zaawansowanym, czy zmianę domyślnego języka C# 5 zmieniać kod autogened? – Kyle

+1

@Kyle, nie ma. Zapomniałem dodać to w moim pytaniu – user2023861

Odpowiedz

8

idź do Narzędzia -> Opcje -> Edytor tekstu -> Code Style -> Ogólne, przejdź do preferencji blokowych Code odcinek i zmienić preferencje Dla właściwości, Dla indeksujących i Dla akcesorów z "Preferuj blok wyrażeń" (domyślnie) na "Preferuj bryłę bryły".

enter image description here

Powiązane problemy