﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CodeAnalysis.CodeStyle
{
    internal partial class CodeStyleOption2<T>
    {
        public static explicit operator CodeStyleOption<T>(CodeStyleOption2<T> option)
        {
            if (option == null)
            {
                return null;
            }

            return new CodeStyleOption<T>(option.Value, (NotificationOption)option.Notification);
        }

        public static explicit operator CodeStyleOption2<T>(CodeStyleOption<T> option)
        {
            if (option == null)
            {
                return null;
            }

            return new CodeStyleOption2<T>(option.Value, (NotificationOption2)option.Notification);
        }
    }
}

﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CodeAnalysis.CodeStyle
{
    internal partial class CodeStyleOption2<T>
    {
        public static implicit operator CodeStyleOption<T>(CodeStyleOption2<T> option)
        {
            if (option == null)
            {
                return null;
            }

            return new CodeStyleOption<T>(option.Value, (NotificationOption)option.Notification);
        }

        public static implicit operator CodeStyleOption2<T>(CodeStyleOption<T> option)
        {
            if (option == null)
            {
                return null;
            }

            return new CodeStyleOption2<T>(option.Value, (NotificationOption2)option.Notification);
        }
    }
}

Switch back to implicit operators for conversions to and from CodeStyleOption and CodeStyleOption2 respectively. These are needed to prevent InvalidCastException when user invokes `optionSet.WithChangedOption(..., new CodeStyleOption<bool>(...))` and any of our internal code base tries to fetch the option value with `optionSet.GetOption<T>(...)` where T is ` CodeStyleOption2<bool>`, and this helper attempts a direct cast from object to `T`.
Switch back to implicit operators for conversions to and from CodeStyleOption and CodeStyleOption2 respectively. These are needed to prevent InvalidCastException when user invokes `optionSet.WithChangedOption(..., new CodeStyleOption<bool>(...))` and any of our internal code base tries to fetch the option value with `optionSet.GetOption<T>(...)` where T is ` CodeStyleOption2<bool>`, and this helper attempts a direct cast from object to `T`.
