Bug Report T442924
Visible to All Users

The "Declare local" code provider should generate an object creation expression instead of the "null" expression when it is possible

created 8 years ago

I seem to recall that CodeRush Classic instantiated objects/lists when using the 'Declare local' refactoring. With Coderush for Roslyn, declared objects are cast to a type, but are left null.  I then have to go back and change the code to new up the object.  Coderush has this behavior even when there is only a default constructor.  For cases when there are multiple constructors, even if I had to pick the constructor (for something like List), doing so would save a lot of typing.

Example:

Code
var items = (List<string>)null; MyMethod(items);
Comments (1)
DevExpress Support Team 8 years ago

    Hi Jonathan.

    Thank you for informing us of this issue.
    >I seem to recall that CodeRush Classic instantiated objects/lists when using the 'Declare local' refactoring.
    > Coderush has this behavior even when there is only a default constructor.
    I agree, the current behavior of "Declare local" should provide the capability to generate object creation (constructor call) as it was in CodeRush Classic.
    We will improve it and notify you in the context of the current ticket.

    > For cases when there are multiple constructors, even if I had to pick the constructor (for something like List), doing so would save a lot of typing.
    Thank you for your suggestion, your idea does have merit.
    I've created a separate ticket on your behalf: 'Declare local' refactoring should request a list of constructors. This issue will be addressed in the context of that ticket.

    Answers approved by DevExpress Support

    created 8 years ago

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.