Repository: PowerShell/PowerShell
File: src/System.Management.Automation/namespaces/FileSystemProvider.cs (C#)

Code before:
                return string.Empty;
            }
            catch (SecurityException)
            {
                return string.Empty;
            }
            catch (XPathException)
            {
                return string.Empty;
            }
            finally
            {
                if (reader != null)
                {
                    ((IDisposable)reader).Dispose();
                }
            }

            return string.Empty;
        }

        #endregion

        #region CmdletProvider members
        // OneDrive placeholder support
#if !UNIX
        [DllImport("ntdll.dll")]
        internal static extern sbyte RtlQueryProcessPlaceholderCompatibilityMode();
        [DllImport("ntdll.dll")]
        internal static extern sbyte RtlSetProcessPlaceholderCompatibilityMode(sbyte pcm);

        internal const sbyte PHCM_APPLICATION_DEFAULT = 0;
        internal const sbyte PHCM_DISGUISE_PLACEHOLDER = 1;
        internal const sbyte PHCM_EXPOSE_PLACEHOLDERS = 2;
        internal const sbyte PHCM_MAX = 2;
        internal const sbyte PHCM_ERROR_INVALID_PARAMETER = -1;
        internal const sbyte PHCM_ERROR_NO_TEB = -2;
#endif

        /// <summary>
        /// Starts the File System provider.  This method sets the Home for the
        /// provider to providerInfo.Home if specified, and %USERPROFILE%
        /// otherwise.
        /// </summary>
        /// <param name="providerInfo">
        /// The ProviderInfo object that holds the provider's configuration.
        /// </param>
        /// <returns>
        /// The updated ProviderInfo object that holds the provider's configuration.
        /// </returns>
        protected override ProviderInfo Start(ProviderInfo providerInfo)

Review comment (refactor):
In this case it is very easy to fix the Code Factor violation "Field names must not contain underscores."
Same file `FileSystemProvider.cs` already has `private static class NativeMethods`, so please move this new P/Invoke things there. Thank you.

Here is the guidance from Code Factor:

> If the field or variable name is intended to match the name of an item associated with Win32 or COM, and thus needs to include underscores, place the field or variable within a special NativeMethods class. A NativeMethods class is any class which contains a name ending in NativeMethods, and is intended as a placeholder for Win32 or COM wrappers. StyleCop will ignore this violation if the item is placed within a NativeMethods class.


Code after:
                return string.Empty;
            }
            catch (SecurityException)
            {
                return string.Empty;
            }
            catch (XPathException)
            {
                return string.Empty;
            }
            finally
            {
                if (reader != null)
                {
                    ((IDisposable)reader).Dispose();
                }
            }

            return string.Empty;
        }

        #endregion

        #region CmdletProvider members
        /// <summary>
        /// Starts the File System provider.  This method sets the Home for the
        /// provider to providerInfo.Home if specified, and %USERPROFILE%
        /// otherwise.
        /// </summary>
        /// <param name="providerInfo">
        /// The ProviderInfo object that holds the provider's configuration.
        /// </param>
        /// <returns>
        /// The updated ProviderInfo object that holds the provider's configuration.
        /// </returns>
        protected override ProviderInfo Start(ProviderInfo providerInfo)
        {
            // Set the home folder for the user
            if (providerInfo != null && string.IsNullOrEmpty(providerInfo.Home))
            {
                // %USERPROFILE% - indicate where a user's home directory is located in the file system.
                string homeDirectory = Environment.GetEnvironmentVariable(Platform.CommonEnvVariableNames.Home);

                if (!string.IsNullOrEmpty(homeDirectory))
                {
                    if (Directory.Exists(homeDirectory))
                    {
                        s_tracer.WriteLine("Home = {0}", homeDirectory);
                        providerInfo.Home = homeDirectory;
                    }
                    else