Ticket T746402
Visible to All Users

How to configure Code Cleanup to avoid this

created 6 years ago

Hi

Consider the following piece of code .

C#
using System; using System.Diagnostics; using System.Linq; using System.Threading; using System.Windows.Forms; namespace WindowsFormsApp1 { static class Program { private static String updaterModulePath; /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { #if DEBUG #else // Start the thread that will launch the updater in silent mode with 10 second delay. Thread thread = new Thread(new ThreadStart(StartSilent)); thread.Start(); // Compute the updater.exe path relative to the application main module path updaterModulePath = Path.Combine(Application.StartupPath, "updater.exe"); #endif Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } private static void StartSilent() { Thread.Sleep(10000); Process process = Process.Start(updaterModulePath, "/silent"); process.Close(); } } }

I rather like the CodeCleanup feature but it exhibits some undesirable effects on a file like this.   Attached is muy settings files.  The problem seems to be with remove unused members, remove unused namespace references, remove unused private types and remove unused types.

If you add for arguments sake a single property to the code above and then invoke save the code designed to run only and runtime in release configuration will be rendered unusable.   I know why but I can't figure out how to stop it happening.  The same goes if I temporarily comment out some code to experiment with different refactoring's.  Various bits that it used will be removed.

Typically when I am pretty certain that I have finished working in a file I will invoke organize members to tidy things up, that's the point at which one really wants most of the cleanup to occur, so How can I retain the cleanup options that I have, retain code formatting particularly on each save and avoid having code that is specifically designed to run at runtime and in release mode only broken in the cleanup process.

Answers approved by DevExpress Support

created 6 years ago (modified 6 years ago)

Hi Dom,
If you are using conditional compilation, 'Remove Unused' code cleanups may not work not as expected because there is no way to determine whether the code is used in other (non-active) configurations - we only have access to data (syntax tree, semantic model) for the active configuration. In this case, I suggest wrapping members and namespace references in conditional compilation directives - it can prevent such code constructions from being unexpectedly deleted. Another possible workaround is to make such members 'public' because public members are not removed on the Remove Unused Member cleanup. The same also works for type declarations.
>Typically when I am pretty certain that I have finished working in a file I will invoke organize members to tidy things up, that's the point at which one really wants most of the cleanup to occur, so How can I retain the cleanup options that I have, retain code >formatting particularly on each save and avoid having code that is specifically designed to run at runtime and in release mode only broken in the cleanup process.
We have plans to implement cleanup profiles - different set of rules for different types of code cleanup (Cleanup on save, Project Cleanup, Document Cleanup). Will such approach work for you?

    Comments (3)

      Hi Alex

      Thank you for getting back to me.  Your suggestion makes sense and I will look into doing that.

      Cleanup Profiles sounds like a good idea.  I'm not sure if this would work but it might make sense for them to be inherited.  Save is the most common action I would argue and so that would contain your basic requirements.  Document would come next so it would equal all in save plus extras.  Project becomes an extension of document …and so on and so on.

      Dom

      AE AE
      Alex Eg (DevExpress) 6 years ago

        Dom,
        We will inform you when this feature is ready, however, I cannot give you any estimations.

        DevExpress Support Team 5 years ago

          Hi Dom,

          We added the possibility of applying different code cleanup settings when the code cleanup action is used and on document saving.
          These changes are available in the latest product version (19.2.3).
          You can read more about this and other improvements on the What's New page

          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.