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

"Use expression body for accessors/properties" generates bad code if body contains #if #19235

Closed
davkean opened this issue May 4, 2017 · 0 comments
Assignees
Milestone

Comments

@davkean
Copy link
Member

davkean commented May 4, 2017

// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.ProjectSystem.Utilities;

namespace Microsoft.VisualStudio.ProjectSystem.VS
{
    [Export(typeof(IProjectSystemOptions))]
    internal class EnvironmentVariableProjectSystemOptions : IProjectSystemOptions
    {
        private readonly IEnvironmentHelper _environment;

        [ImportingConstructor]
        public EnvironmentVariableProjectSystemOptions(IEnvironmentHelper environment)
        {
            Requires.NotNull(environment, nameof(environment));

            _environment = environment;
        }

        public bool IsProjectOutputPaneEnabled
        {
            get
            {
#if DEBUG
                return true;
#else
                return IsEnabled("PROJECTSYSTEM_PROJECTOUTPUTPANEENABLED");
#endif
            }
        }

        private bool IsEnabled(string variable)
        {
            string value = _environment.GetEnvironmentVariable(variable);

            return string.Equals(value, "1", StringComparison.OrdinalIgnoreCase);
        }
    }
}

Use expression body for accessors:

// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.ProjectSystem.Utilities;

namespace Microsoft.VisualStudio.ProjectSystem.VS
{
    [Export(typeof(IProjectSystemOptions))]
    internal class EnvironmentVariableProjectSystemOptions : IProjectSystemOptions
    {
        private readonly IEnvironmentHelper _environment;

        [ImportingConstructor]
        public EnvironmentVariableProjectSystemOptions(IEnvironmentHelper environment)
        {
            Requires.NotNull(environment, nameof(environment));

            _environment = environment;
        }

        public bool IsProjectOutputPaneEnabled
        {
            get => true;
#else
                return IsEnabled("PROJECTSYSTEM_PROJECTOUTPUTPANEENABLED");
#endif

        }

        private bool IsEnabled(string variable)
        {
            string value = _environment.GetEnvironmentVariable(variable);

            return string.Equals(value, "1", StringComparison.OrdinalIgnoreCase);
        }
    }
}

        }

Use expression body for properties:

// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.ProjectSystem.Utilities;

namespace Microsoft.VisualStudio.ProjectSystem.VS
{
    [Export(typeof(IProjectSystemOptions))]
    internal class EnvironmentVariableProjectSystemOptions : IProjectSystemOptions
    {
        private readonly IEnvironmentHelper _environment;

        [ImportingConstructor]
        public EnvironmentVariableProjectSystemOptions(IEnvironmentHelper environment)
        {
            Requires.NotNull(environment, nameof(environment));

            _environment = environment;
        }

        public bool IsProjectOutputPaneEnabled => true;
#else
                return IsEnabled("PROJECTSYSTEM_PROJECTOUTPUTPANEENABLED");
#endif


        private bool IsEnabled(string variable)
        {
            string value = _environment.GetEnvironmentVariable(variable);

            return string.Equals(value, "1", StringComparison.OrdinalIgnoreCase);
        }
    }
}
@davkean davkean changed the title "Use expression body for accessors/properties" generates bad code for #if "Use expression body for accessors/properties" generates bad code if body contains #if May 4, 2017
@gafter gafter added the Area-IDE label May 4, 2017
@Pilchie Pilchie added the Bug label May 4, 2017
@Pilchie Pilchie added this to the 15.3 milestone May 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants