Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update "propdp" snippet to use nameof #44551

Closed
vsfeedback opened this issue May 26, 2020 · 6 comments
Closed

Update "propdp" snippet to use nameof #44551

vsfeedback opened this issue May 26, 2020 · 6 comments
Labels
Area-IDE Blocked Concept-Continuous Improvement Developer Community The issue was originally reported on https://developercommunity.visualstudio.com IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


The propdp C# code snippet creates the following code:

public int MyProperty
{
    get { return (int)GetValue(MyPropertyProperty); }
    set { SetValue(MyPropertyProperty, value); }
}

// Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
    DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));

Notice the "MyProperty" string literal, which points to the backing property for the dependency property. This is not ideal, because renaming the property will not change this string and will cause unexpected problems at runtime. Instead, the code snippet could generate the following:

...
public static readonly DependencyProperty MyPropertyProperty =
    DependencyProperty.Register(nameof(MyProperty), typeof(int), typeof(ownerclass), new PropertyMetadata(0));

Using the nameof operator, the code would gain compile time safety and would automatically update the reference whenever the property name changes.


Original Comments

Visual Studio Feedback System on 5/25/2020, 03:06 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

@jinujoseph jinujoseph added Area-IDE Concept-Continuous Improvement Developer Community The issue was originally reported on https://developercommunity.visualstudio.com help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings labels May 26, 2020
@jinujoseph jinujoseph added this to the Backlog milestone May 26, 2020
@DaveInCaz
Copy link

I'm curious why this got filed under the roslyn project? Isn't' that the compiler engine? This just seems like a Visual Studio feature.

@CyrusNajmabadi
Copy link
Member

Roslyn supplies the VS IDE side of thing for C#/VB and portions of F#/TS/JS/Xaml.

@sharwell
Copy link
Member

sharwell commented Nov 5, 2020

Blocked on #31879

@sharwell sharwell added Blocked and removed help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Nov 5, 2020
@DaveInCaz
Copy link

FWIW there is a StackOverflow post which gets some notice about this same issue. It proposes a local workaround for developers to modify the snippet file.

https://stackoverflow.com/q/35392084/3195477

@DaveInCaz
Copy link

DaveInCaz commented Nov 17, 2021

Is this a dupe of #5574 ?

(@sharwell I suggest closing this as a dupe of that one?)

@sharwell
Copy link
Member

Duplicate of #5574

@sharwell sharwell marked this as a duplicate of #5574 Jul 18, 2023
@sharwell sharwell closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Blocked Concept-Continuous Improvement Developer Community The issue was originally reported on https://developercommunity.visualstudio.com IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Projects
None yet
Development

No branches or pull requests

5 participants